vislite 0.8.0 → 0.8.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG +212 -209
  2. package/README.md +136 -144
  3. package/lib/Buffer/index.umd.js +36 -36
  4. package/lib/Buffer/index.umd.min.js +2 -2
  5. package/lib/Canvas/index.umd.js +691 -691
  6. package/lib/Canvas/index.umd.min.js +2 -2
  7. package/lib/Cardinal/index.umd.js +91 -91
  8. package/lib/Cardinal/index.umd.min.js +2 -2
  9. package/lib/Eoap/index.umd.js +34 -34
  10. package/lib/Eoap/index.umd.min.js +2 -2
  11. package/lib/Geometry/index.umd.js +286 -286
  12. package/lib/Geometry/index.umd.min.js +2 -2
  13. package/lib/Hermite/index.umd.js +36 -36
  14. package/lib/Hermite/index.umd.min.js +2 -2
  15. package/lib/Matrix4/index.umd.js +125 -125
  16. package/lib/Matrix4/index.umd.min.js +2 -2
  17. package/lib/Mercator/index.umd.js +20 -20
  18. package/lib/Mercator/index.umd.min.js +2 -2
  19. package/lib/OralCanvas/index.es.js +634 -634
  20. package/lib/OralCanvas/index.es.min.js +2 -2
  21. package/lib/OralWebGL/index.es.js +552 -552
  22. package/lib/OralWebGL/index.es.min.js +2 -2
  23. package/lib/SVG/index.umd.js +471 -471
  24. package/lib/SVG/index.umd.min.js +2 -2
  25. package/lib/Shader/index.umd.js +61 -61
  26. package/lib/Shader/index.umd.min.js +2 -2
  27. package/lib/Texture/index.umd.js +54 -54
  28. package/lib/Texture/index.umd.min.js +2 -2
  29. package/lib/TreeLayout/index.umd.js +368 -368
  30. package/lib/TreeLayout/index.umd.min.js +2 -2
  31. package/lib/WebGL/index.umd.js +599 -599
  32. package/lib/WebGL/index.umd.min.js +2 -2
  33. package/lib/animation/index.umd.js +73 -73
  34. package/lib/animation/index.umd.min.js +2 -2
  35. package/lib/formatColor/index.umd.js +40 -40
  36. package/lib/formatColor/index.umd.min.js +2 -2
  37. package/lib/getLoopColors/index.umd.js +36 -36
  38. package/lib/getLoopColors/index.umd.min.js +2 -2
  39. package/lib/getWebGLContext/index.umd.js +63 -63
  40. package/lib/getWebGLContext/index.umd.min.js +2 -2
  41. package/lib/index.umd.js +2955 -2955
  42. package/lib/index.umd.min.js +2 -2
  43. package/lib/move/index.umd.js +8 -8
  44. package/lib/move/index.umd.min.js +2 -2
  45. package/lib/resizeObserver/index.umd.js +30 -30
  46. package/lib/resizeObserver/index.umd.min.js +2 -2
  47. package/lib/rotate/index.umd.js +8 -8
  48. package/lib/rotate/index.umd.min.js +2 -2
  49. package/lib/ruler/index.umd.js +138 -138
  50. package/lib/ruler/index.umd.min.js +2 -2
  51. package/lib/scale/index.umd.js +7 -7
  52. package/lib/scale/index.umd.min.js +2 -2
  53. package/lib/throttle/index.umd.js +49 -49
  54. package/lib/throttle/index.umd.min.js +2 -2
  55. package/lib/viewHandler/index.umd.js +120 -120
  56. package/lib/viewHandler/index.umd.min.js +2 -2
  57. package/miniprogram/ui-canvas/drawImage.js +34 -0
  58. package/miniprogram/ui-canvas/index.js +10 -2
  59. package/package/getWebGLContext/index.ts +40 -40
  60. package/package.json +70 -70
  61. package/src/Canvas.ts +72 -72
  62. package/src/Geometry.ts +210 -210
  63. package/src/WebGL.ts +66 -66
  64. package/src/common/canvas/index.ts +183 -183
  65. package/src/common/canvas/painter.ts +446 -446
  66. package/src/common/geometry/prism-horizontal.ts +50 -50
  67. package/src/common/geometry/prism-vertical.ts +55 -55
  68. package/src/common/geometry/tool/circle.ts +17 -17
  69. package/src/common/geometry/tool/rotateLine.ts +48 -48
  70. package/src/common/geometry/tool/triangles.ts +23 -23
  71. package/src/common/webgl/getWebGLContext.ts +45 -45
  72. package/src/common/webgl/index.ts +227 -227
  73. package/types/Canvas.d.ts +318 -318
  74. package/types/Geometry.d.ts +132 -132
  75. package/types/WebGLOption.d.ts +14 -14
  76. package/types/getWebGLContext.d.ts +4 -4
  77. package/types/ui-canvas.d.ts +4 -4
  78. package/uni-app/drawImage.js +17 -17
  79. package/uni-app/ui-canvas.vue +290 -290
@@ -1,50 +1,50 @@
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
- }
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
+ }
@@ -1,55 +1,55 @@
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 height 高
11
- * @param num 份数
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, height: number, num: number, beginDeg: number = 0, deg: number = Math.PI * 2) {
17
- const points = []
18
- let beginPosition: [number, number]
19
-
20
- if (num == 4) {
21
- beginPosition = rotate(x, z, Math.PI * 0.25, x - radius, z)
22
- } else {
23
- beginPosition = [x + radius, z]
24
- }
25
-
26
- if (beginDeg != 0) {
27
- beginPosition = rotate(x, z, beginDeg, ...beginPosition)
28
- }
29
-
30
- const perDeg = deg / num, degHalf = deg / (num * 2)
31
-
32
- let endPosition: [number, number], normalPosition: [number, number, number] | [] = []
33
- for (let i = 0; i < num; i++) {
34
-
35
- endPosition = rotate(x, z, perDeg, ...beginPosition)
36
-
37
- if (normal) {
38
- const halfPosition = rotate(x, z, degHalf, ...beginPosition)
39
- normalPosition = [halfPosition[0], 0, halfPosition[1]]
40
- }
41
-
42
- points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
43
- points.push(beginPosition[0], y + height, beginPosition[1], ...normalPosition)
44
- points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
45
-
46
- points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
47
- points.push(endPosition[0], y, endPosition[1], ...normalPosition)
48
- points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
49
-
50
-
51
- beginPosition = endPosition
52
- }
53
-
54
- return points
55
- }
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 height 高
11
+ * @param num 份数
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, height: number, num: number, beginDeg: number = 0, deg: number = Math.PI * 2) {
17
+ const points = []
18
+ let beginPosition: [number, number]
19
+
20
+ if (num == 4) {
21
+ beginPosition = rotate(x, z, Math.PI * 0.25, x - radius, z)
22
+ } else {
23
+ beginPosition = [x + radius, z]
24
+ }
25
+
26
+ if (beginDeg != 0) {
27
+ beginPosition = rotate(x, z, beginDeg, ...beginPosition)
28
+ }
29
+
30
+ const perDeg = deg / num, degHalf = deg / (num * 2)
31
+
32
+ let endPosition: [number, number], normalPosition: [number, number, number] | [] = []
33
+ for (let i = 0; i < num; i++) {
34
+
35
+ endPosition = rotate(x, z, perDeg, ...beginPosition)
36
+
37
+ if (normal) {
38
+ const halfPosition = rotate(x, z, degHalf, ...beginPosition)
39
+ normalPosition = [halfPosition[0], 0, halfPosition[1]]
40
+ }
41
+
42
+ points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
43
+ points.push(beginPosition[0], y + height, beginPosition[1], ...normalPosition)
44
+ points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
45
+
46
+ points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
47
+ points.push(endPosition[0], y, endPosition[1], ...normalPosition)
48
+ points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
49
+
50
+
51
+ beginPosition = endPosition
52
+ }
53
+
54
+ return points
55
+ }
@@ -1,18 +1,18 @@
1
- /**
2
- * 计算切割份数
3
- * @param precision 精度
4
- * @param radius 半径
5
- * @param deg 需要跨越的弧度,默认圆(2pi)
6
- * @returns 切割份数
7
- */
8
- export const splitNum = function (precision: number, radius: number, deg: number = Math.PI * 2) {
9
-
10
- // 根据切割弧度得出切割块数目
11
- const num = Math.ceil(deg /
12
-
13
- // 为了满足最小精度而得出的切割弧度
14
- Math.asin(precision / radius) * 2)
15
-
16
- return (isNaN(num) || num < 12) ? 12 : num
17
-
1
+ /**
2
+ * 计算切割份数
3
+ * @param precision 精度
4
+ * @param radius 半径
5
+ * @param deg 需要跨越的弧度,默认圆(2pi)
6
+ * @returns 切割份数
7
+ */
8
+ export const splitNum = function (precision: number, radius: number, deg: number = Math.PI * 2) {
9
+
10
+ // 根据切割弧度得出切割块数目
11
+ const num = Math.ceil(deg /
12
+
13
+ // 为了满足最小精度而得出的切割弧度
14
+ Math.asin(precision / radius) * 2)
15
+
16
+ return (isNaN(num) || num < 12) ? 12 : num
17
+
18
18
  }
@@ -1,49 +1,49 @@
1
- /**
2
- * 物体方向转换
3
- * 由(x,y,z)转换成(x2-x,y2-y,z2-z)
4
- * @param x
5
- * @param y
6
- * @param z
7
- * @param x2
8
- * @param y2
9
- * @param z2
10
- * @returns 点转换函数
11
- */
12
- export default function (x: number, y: number, z: number, x2: number, y2: number, z2: number) {
13
- return (x0: number, y0: number, z0: number, isNormal: boolean) => {
14
- if (x == x2 && z == z2) return [x0, y0, z0]
15
-
16
- let sin: number, cos: number, temp: Array<number>
17
-
18
- // 第一步:归零化
19
- let _x0 = x0 - (isNormal ? 0 : x), _y0 = y0 - (isNormal ? 0 : y), _z0 = z0 - (isNormal ? 0 : z) // 法向量起点本来就是原点
20
- const _x2 = x2 - x, _y2 = y2 - y, _z2 = z2 - z
21
-
22
- // 第二步:围绕OZ轴旋转
23
-
24
- const __d = Math.sqrt(_x2 * _x2 + _z2 * _z2)
25
- cos = _x2 / __d
26
- sin = _z2 / __d
27
-
28
- const _x2N = _z2 * sin + _x2 * cos
29
-
30
- const d = Math.sqrt(_y2 * _y2 + _x2N * _x2N)
31
- cos = _y2 / d
32
- sin = _x2N / d
33
-
34
- temp = [_y0, _x0]
35
- _y0 = temp[0] * cos - temp[1] * sin
36
- _x0 = temp[0] * sin + temp[1] * cos
37
-
38
- // 第三步:围绕0Y轴旋转
39
- cos = _x2 / __d
40
- sin = _z2 / __d
41
-
42
- temp = [_x0, _z0]
43
- _x0 = temp[0] * cos - temp[1] * sin
44
- _z0 = temp[0] * sin + temp[1] * cos
45
-
46
- // 第四步:去零化(直接返回)
47
- return [_x0 + (isNormal ? 0 : x), _y0 + (isNormal ? 0 : y), _z0 + (isNormal ? 0 : z)]
48
- }
1
+ /**
2
+ * 物体方向转换
3
+ * 由(x,y,z)转换成(x2-x,y2-y,z2-z)
4
+ * @param x
5
+ * @param y
6
+ * @param z
7
+ * @param x2
8
+ * @param y2
9
+ * @param z2
10
+ * @returns 点转换函数
11
+ */
12
+ export default function (x: number, y: number, z: number, x2: number, y2: number, z2: number) {
13
+ return (x0: number, y0: number, z0: number, isNormal: boolean) => {
14
+ if (x == x2 && z == z2) return [x0, y0, z0]
15
+
16
+ let sin: number, cos: number, temp: Array<number>
17
+
18
+ // 第一步:归零化
19
+ let _x0 = x0 - (isNormal ? 0 : x), _y0 = y0 - (isNormal ? 0 : y), _z0 = z0 - (isNormal ? 0 : z) // 法向量起点本来就是原点
20
+ const _x2 = x2 - x, _y2 = y2 - y, _z2 = z2 - z
21
+
22
+ // 第二步:围绕OZ轴旋转
23
+
24
+ const __d = Math.sqrt(_x2 * _x2 + _z2 * _z2)
25
+ cos = _x2 / __d
26
+ sin = _z2 / __d
27
+
28
+ const _x2N = _z2 * sin + _x2 * cos
29
+
30
+ const d = Math.sqrt(_y2 * _y2 + _x2N * _x2N)
31
+ cos = _y2 / d
32
+ sin = _x2N / d
33
+
34
+ temp = [_y0, _x0]
35
+ _y0 = temp[0] * cos - temp[1] * sin
36
+ _x0 = temp[0] * sin + temp[1] * cos
37
+
38
+ // 第三步:围绕0Y轴旋转
39
+ cos = _x2 / __d
40
+ sin = _z2 / __d
41
+
42
+ temp = [_x0, _z0]
43
+ _x0 = temp[0] * cos - temp[1] * sin
44
+ _z0 = temp[0] * sin + temp[1] * cos
45
+
46
+ // 第四步:去零化(直接返回)
47
+ return [_x0 + (isNormal ? 0 : x), _y0 + (isNormal ? 0 : y), _z0 + (isNormal ? 0 : z)]
48
+ }
49
49
  }
@@ -1,24 +1,24 @@
1
- /**
2
- * 方向:ab x ac
3
- * @param normal 是否需要法向量
4
- * @param points [a1, b1, c1, a2, b2, c2, ...]
5
- * @returns 完整的点数据
6
- */
7
- export default function (normal: boolean, points: Array<number>) {
8
- if (normal) {
9
- const _points = []
10
- for (let i = 0; i < points.length; i += 9) {
11
- const ab = [points[i + 3] - points[i], points[i + 4] - points[i + 1], points[i + 5] - points[i + 2]]
12
- const ac = [points[i + 6] - points[i], points[i + 7] - points[i + 1], points[i + 8] - points[i + 2]]
13
- const normalVector = [ab[1] * ac[2] - ac[1] * ab[2], ab[2] * ac[0] - ab[0] * ac[2], ab[0] * ac[1] - ab[1] * ac[2]]
14
- _points.push(
15
- points[i], points[i + 1], points[i + 2], ...normalVector,
16
- points[i + 3], points[i + 4], points[i + 5], ...normalVector,
17
- points[i + 6], points[i + 7], points[i + 8], ...normalVector,
18
- )
19
- }
20
- return _points
21
- } else {
22
- return points
23
- }
1
+ /**
2
+ * 方向:ab x ac
3
+ * @param normal 是否需要法向量
4
+ * @param points [a1, b1, c1, a2, b2, c2, ...]
5
+ * @returns 完整的点数据
6
+ */
7
+ export default function (normal: boolean, points: Array<number>) {
8
+ if (normal) {
9
+ const _points = []
10
+ for (let i = 0; i < points.length; i += 9) {
11
+ const ab = [points[i + 3] - points[i], points[i + 4] - points[i + 1], points[i + 5] - points[i + 2]]
12
+ const ac = [points[i + 6] - points[i], points[i + 7] - points[i + 1], points[i + 8] - points[i + 2]]
13
+ const normalVector = [ab[1] * ac[2] - ac[1] * ab[2], ab[2] * ac[0] - ab[0] * ac[2], ab[0] * ac[1] - ab[1] * ac[2]]
14
+ _points.push(
15
+ points[i], points[i + 1], points[i + 2], ...normalVector,
16
+ points[i + 3], points[i + 4], points[i + 5], ...normalVector,
17
+ points[i + 6], points[i + 7], points[i + 8], ...normalVector,
18
+ )
19
+ }
20
+ return _points
21
+ } else {
22
+ return points
23
+ }
24
24
  }
@@ -1,46 +1,46 @@
1
- import type { WebGLmodeType } from "../../../types/getWebGLContext"
2
-
3
- interface OptsType {
4
- preserveDrawingBuffer?: boolean
5
- }
6
- export default function (canvas: HTMLCanvasElement, scale: number, opts: OptsType = {}, mode: WebGLmodeType = "scaleToFill") {
7
- const names = ["experimental-webgl", "webkit-3d", "moz-webgl"]
8
- let painter = canvas.getContext("webgl", opts) as WebGL2RenderingContext
9
- for (let i = 0; i < names.length; i++) {
10
- try {
11
- painter = canvas.getContext(names[i], opts) as WebGL2RenderingContext
12
- } catch (e) { }
13
- if (painter) break
14
- }
15
- if (!painter) throw new Error('Non canvas or browser does not support webgl.')
16
-
17
- const width = painter.canvas.width, height = painter.canvas.height
18
-
19
- let scaleX = scale, scaleY = scale
20
- if (mode == "aspectFit") {
21
- if (width > height) {
22
- scaleX *= height / width
23
- } else if (height > width) {
24
- scaleY *= width / height
25
- }
26
- } else if (mode == "aspectFill") {
27
- if (width > height) {
28
- scaleY *= width / height
29
- } else if (height > width) {
30
- scaleX *= height / width
31
- }
32
- }
33
-
34
- const viewWidth = width * scaleX
35
- const viewHeight = height * scaleY
36
-
37
- painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight)
38
-
39
- // https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/depthFunc
40
- painter.depthFunc(painter.LEQUAL)
41
-
42
- // 开启深度计算
43
- painter.enable(painter.DEPTH_TEST);
44
-
45
- return painter
1
+ import type { WebGLmodeType } from "../../../types/getWebGLContext"
2
+
3
+ interface OptsType {
4
+ preserveDrawingBuffer?: boolean
5
+ }
6
+ export default function (canvas: HTMLCanvasElement, scale: number, opts: OptsType = {}, mode: WebGLmodeType = "scaleToFill") {
7
+ const names = ["experimental-webgl", "webkit-3d", "moz-webgl"]
8
+ let painter = canvas.getContext("webgl", opts) as WebGL2RenderingContext
9
+ for (let i = 0; i < names.length; i++) {
10
+ try {
11
+ painter = canvas.getContext(names[i], opts) as WebGL2RenderingContext
12
+ } catch (e) { }
13
+ if (painter) break
14
+ }
15
+ if (!painter) throw new Error('Non canvas or browser does not support webgl.')
16
+
17
+ const width = painter.canvas.width, height = painter.canvas.height
18
+
19
+ let scaleX = scale, scaleY = scale
20
+ if (mode == "aspectFit") {
21
+ if (width > height) {
22
+ scaleX *= height / width
23
+ } else if (height > width) {
24
+ scaleY *= width / height
25
+ }
26
+ } else if (mode == "aspectFill") {
27
+ if (width > height) {
28
+ scaleY *= width / height
29
+ } else if (height > width) {
30
+ scaleX *= height / width
31
+ }
32
+ }
33
+
34
+ const viewWidth = width * scaleX
35
+ const viewHeight = height * scaleY
36
+
37
+ painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight)
38
+
39
+ // https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/depthFunc
40
+ painter.depthFunc(painter.LEQUAL)
41
+
42
+ // 开启深度计算
43
+ painter.enable(painter.DEPTH_TEST);
44
+
45
+ return painter
46
46
  }