vislite 0.3.1 → 0.4.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 (128) hide show
  1. package/AUTHORS.txt +6 -6
  2. package/CHANGELOG +7 -1
  3. package/LICENSE +20 -20
  4. package/README.md +53 -53
  5. package/lib/Buffer/index.umd.js +2 -2
  6. package/lib/Buffer/index.umd.min.js +2 -2
  7. package/lib/Canvas/index.umd.js +9 -2
  8. package/lib/Canvas/index.umd.min.js +3 -3
  9. package/lib/Cardinal/index.umd.js +2 -2
  10. package/lib/Cardinal/index.umd.min.js +2 -2
  11. package/lib/Eoap/index.umd.js +2 -2
  12. package/lib/Eoap/index.umd.min.js +2 -2
  13. package/lib/Hermite/index.umd.js +2 -2
  14. package/lib/Hermite/index.umd.min.js +2 -2
  15. package/lib/Matrix4/index.umd.js +2 -2
  16. package/lib/Matrix4/index.umd.min.js +2 -2
  17. package/lib/Mercator/index.umd.js +2 -2
  18. package/lib/Mercator/index.umd.min.js +2 -2
  19. package/lib/OralCanvas/index.es.js +9 -2
  20. package/lib/OralCanvas/index.es.min.js +3 -3
  21. package/lib/OralWebGL/index.es.js +2 -2
  22. package/lib/OralWebGL/index.es.min.js +2 -2
  23. package/lib/SVG/index.umd.js +2 -2
  24. package/lib/SVG/index.umd.min.js +2 -2
  25. package/lib/Shader/index.umd.js +2 -2
  26. package/lib/Shader/index.umd.min.js +2 -2
  27. package/lib/Texture/index.umd.js +2 -2
  28. package/lib/Texture/index.umd.min.js +2 -2
  29. package/lib/WebGL/index.umd.js +2 -2
  30. package/lib/WebGL/index.umd.min.js +2 -2
  31. package/lib/animation/index.umd.js +2 -2
  32. package/lib/animation/index.umd.min.js +2 -2
  33. package/lib/getLoopColors/index.umd.js +2 -2
  34. package/lib/getLoopColors/index.umd.min.js +2 -2
  35. package/lib/getWebGLContext/index.umd.js +2 -2
  36. package/lib/getWebGLContext/index.umd.min.js +2 -2
  37. package/lib/index.umd.js +9 -2
  38. package/lib/index.umd.min.js +3 -3
  39. package/lib/rotate/index.umd.js +2 -2
  40. package/lib/rotate/index.umd.min.js +2 -2
  41. package/lib/ruler/index.umd.js +2 -2
  42. package/lib/ruler/index.umd.min.js +2 -2
  43. package/lib/viewHandler/index.umd.js +2 -2
  44. package/lib/viewHandler/index.umd.min.js +2 -2
  45. package/miniprogram/ui-canvas/index.js +99 -99
  46. package/miniprogram/ui-canvas/index.json +4 -4
  47. package/miniprogram/ui-canvas/index.wxml +4 -4
  48. package/miniprogram/ui-canvas/index.wxss +5 -5
  49. package/package/Buffer/index.ts +1 -1
  50. package/package/Canvas/index.ts +1 -1
  51. package/package/Cardinal/index.ts +2 -2
  52. package/package/Eoap/index.ts +2 -2
  53. package/package/Hermite/index.ts +2 -2
  54. package/package/Matrix4/index.ts +2 -2
  55. package/package/Mercator/index.ts +2 -2
  56. package/package/OralCanvas/index.ts +1 -1
  57. package/package/OralWebGL/index.ts +1 -1
  58. package/package/SVG/index.ts +2 -2
  59. package/package/Shader/index.ts +1 -1
  60. package/package/Texture/index.ts +1 -1
  61. package/package/WebGL/index.ts +1 -1
  62. package/package/animation/index.ts +2 -2
  63. package/package/getLoopColors/index.ts +2 -2
  64. package/package/getWebGLContext/index.ts +39 -39
  65. package/package/index.ts +56 -56
  66. package/package/rotate/index.ts +2 -2
  67. package/package/ruler/index.ts +2 -2
  68. package/package/viewHandler/index.ts +2 -2
  69. package/package.json +2 -2
  70. package/src/Canvas.ts +56 -56
  71. package/src/Eoap.ts +66 -66
  72. package/src/Matrix4/index.ts +76 -76
  73. package/src/Matrix4/move.ts +12 -12
  74. package/src/Matrix4/rotate.ts +15 -15
  75. package/src/Matrix4/scale.ts +11 -11
  76. package/src/Matrix4/transform.ts +64 -64
  77. package/src/Mercator.ts +26 -26
  78. package/src/SVG.ts +23 -23
  79. package/src/WebGL.ts +52 -52
  80. package/src/animation.ts +99 -99
  81. package/src/common/canvas/arc.ts +50 -50
  82. package/src/common/canvas/config.ts +157 -157
  83. package/src/common/canvas/gradient.ts +29 -29
  84. package/src/common/canvas/index.ts +14 -0
  85. package/src/common/canvas/painter.ts +355 -355
  86. package/src/common/canvas/texts.ts +18 -18
  87. package/src/common/setStyle.ts +5 -5
  88. package/src/common/svg/config.ts +173 -173
  89. package/src/common/svg/index.ts +334 -334
  90. package/src/common/svg/tool.ts +43 -43
  91. package/src/common/webgl/buffer.ts +79 -79
  92. package/src/common/webgl/doDraw.ts +106 -106
  93. package/src/common/webgl/getColorFactory.ts +26 -26
  94. package/src/common/webgl/getShader.ts +75 -75
  95. package/src/common/webgl/getTexture.ts +11 -11
  96. package/src/common/webgl/getWebGLContext.ts +27 -27
  97. package/src/common/webgl/index.ts +216 -216
  98. package/src/common/webgl/shader.ts +75 -75
  99. package/src/common/webgl/texture.ts +99 -99
  100. package/src/getLoopColors.ts +42 -42
  101. package/src/interpolation/Cardinal.ts +109 -109
  102. package/src/interpolation/Hermite.ts +65 -65
  103. package/src/rotate.ts +7 -7
  104. package/src/ruler.ts +99 -99
  105. package/src/viewHandler.ts +139 -139
  106. package/types/Buffer.d.ts +23 -23
  107. package/types/Canvas.d.ts +288 -282
  108. package/types/CanvasConfig.d.ts +80 -80
  109. package/types/Cardinal.d.ts +13 -13
  110. package/types/Gradient.d.ts +14 -14
  111. package/types/Hermite.d.ts +18 -18
  112. package/types/Map.d.ts +9 -9
  113. package/types/Matrix4.d.ts +42 -42
  114. package/types/Object3D.d.ts +113 -113
  115. package/types/SVG.d.ts +210 -210
  116. package/types/SVGConfig.d.ts +58 -58
  117. package/types/Scene3D.d.ts +6 -6
  118. package/types/Shader.d.ts +15 -15
  119. package/types/Texture.d.ts +16 -16
  120. package/types/WebGL.d.ts +38 -38
  121. package/types/animation.d.ts +6 -6
  122. package/types/getLoopColors.d.ts +2 -2
  123. package/types/getWebGLContext.d.ts +2 -2
  124. package/types/index.d.ts +129 -129
  125. package/types/rotate.d.ts +2 -2
  126. package/types/ruler.d.ts +2 -2
  127. package/types/viewHandler.d.ts +12 -12
  128. package/uni-app/ui-canvas.vue +212 -212
@@ -1,66 +1,66 @@
1
- import HermiteType from '../../types/Hermite'
2
-
3
- class Hermite implements HermiteType {
4
- readonly name: string = 'Hermite'
5
-
6
- private __u: number // 张弛系数
7
-
8
- private __MR: number[]
9
- private __a: number
10
- private __b: number
11
-
12
- constructor(u: number = 0.5) {
13
- this.__u = u
14
- }
15
-
16
- /**
17
- * 设置点的位置
18
- * @param {Number} x1 左边点的位置
19
- * @param {Number} y1
20
- * @param {Number} x2 右边点的位置
21
- * @param {Number} y2
22
- * @param {Number} s1 两个点的斜率
23
- * @param {Number} s2
24
- */
25
- setP(x1: number, y1: number, x2: number, y2: number, s1: number, s2: number) {
26
- if (x1 < x2) {
27
- // 记录原始尺寸
28
- this.__a = x1
29
- this.__b = x2
30
- let p3 = this.__u * s1,
31
- p4 = this.__u * s2
32
- // 缩放到[0,1]定义域
33
- y1 /= (x2 - x1)
34
- y2 /= (x2 - x1)
35
- // MR是提前计算好的多项式通解矩阵
36
- // 为了加速计算
37
- // 如上面说的
38
- // 统一在[0,1]上计算后再通过缩放和移动恢复
39
- // 避免了动态求解矩阵的麻烦
40
- this.__MR = [
41
- 2 * y1 - 2 * y2 + p3 + p4,
42
- 3 * y2 - 3 * y1 - 2 * p3 - p4,
43
- p3,
44
- y1
45
- ]
46
- } else throw new Error('The point x-position should be increamented!')
47
- return this
48
- }
49
-
50
-
51
- /**
52
- * 根据x值返回y值
53
- * @param {Number} x
54
- */
55
- use(x: number) {
56
- if (this.__MR) {
57
- let sx = (x - this.__a) / (this.__b - this.__a),
58
- sx2 = sx * sx,
59
- sx3 = sx * sx2
60
- let sResult = sx3 * this.__MR[0] + sx2 * this.__MR[1] + sx * this.__MR[2] + this.__MR[3]
61
- return sResult * (this.__b - this.__a)
62
- } else throw new Error('You shoud first set the position!')
63
- }
64
- }
65
-
1
+ import HermiteType from '../../types/Hermite'
2
+
3
+ class Hermite implements HermiteType {
4
+ readonly name: string = 'Hermite'
5
+
6
+ private __u: number // 张弛系数
7
+
8
+ private __MR: number[]
9
+ private __a: number
10
+ private __b: number
11
+
12
+ constructor(u: number = 0.5) {
13
+ this.__u = u
14
+ }
15
+
16
+ /**
17
+ * 设置点的位置
18
+ * @param {Number} x1 左边点的位置
19
+ * @param {Number} y1
20
+ * @param {Number} x2 右边点的位置
21
+ * @param {Number} y2
22
+ * @param {Number} s1 两个点的斜率
23
+ * @param {Number} s2
24
+ */
25
+ setP(x1: number, y1: number, x2: number, y2: number, s1: number, s2: number) {
26
+ if (x1 < x2) {
27
+ // 记录原始尺寸
28
+ this.__a = x1
29
+ this.__b = x2
30
+ let p3 = this.__u * s1,
31
+ p4 = this.__u * s2
32
+ // 缩放到[0,1]定义域
33
+ y1 /= (x2 - x1)
34
+ y2 /= (x2 - x1)
35
+ // MR是提前计算好的多项式通解矩阵
36
+ // 为了加速计算
37
+ // 如上面说的
38
+ // 统一在[0,1]上计算后再通过缩放和移动恢复
39
+ // 避免了动态求解矩阵的麻烦
40
+ this.__MR = [
41
+ 2 * y1 - 2 * y2 + p3 + p4,
42
+ 3 * y2 - 3 * y1 - 2 * p3 - p4,
43
+ p3,
44
+ y1
45
+ ]
46
+ } else throw new Error('The point x-position should be increamented!')
47
+ return this
48
+ }
49
+
50
+
51
+ /**
52
+ * 根据x值返回y值
53
+ * @param {Number} x
54
+ */
55
+ use(x: number) {
56
+ if (this.__MR) {
57
+ let sx = (x - this.__a) / (this.__b - this.__a),
58
+ sx2 = sx * sx,
59
+ sx3 = sx * sx2
60
+ let sResult = sx3 * this.__MR[0] + sx2 * this.__MR[1] + sx * this.__MR[2] + this.__MR[3]
61
+ return sResult * (this.__b - this.__a)
62
+ } else throw new Error('You shoud first set the position!')
63
+ }
64
+ }
65
+
66
66
  export default Hermite
package/src/rotate.ts CHANGED
@@ -1,8 +1,8 @@
1
- // 点(x,y)围绕中心(cx,cy)旋转deg度
2
- export default function (cx: number, cy: number, deg: number, x: number, y: number) {
3
- let cos = Math.cos(deg), sin = Math.sin(deg)
4
- return [
5
- (x - cx) * cos - (y - cy) * sin + cx,
6
- (x - cx) * sin + (y - cy) * cos + cy
7
- ]
1
+ // 点(x,y)围绕中心(cx,cy)旋转deg度
2
+ export default function (cx: number, cy: number, deg: number, x: number, y: number) {
3
+ let cos = Math.cos(deg), sin = Math.sin(deg)
4
+ return [
5
+ (x - cx) * cos - (y - cy) * sin + cx,
6
+ (x - cx) * sin + (y - cy) * cos + cy
7
+ ]
8
8
  }
package/src/ruler.ts CHANGED
@@ -1,99 +1,99 @@
1
- // 刻度尺刻度求解
2
-
3
- // 需要注意的是,实际的间距个数可能是 num-1 或 num 或 num+1 或 1
4
- export default function (maxValue: number, minValue: number, num: number) {
5
-
6
- // 如果最大值最小值反了
7
- if (maxValue < minValue) {
8
- let temp = minValue
9
- minValue = maxValue
10
- maxValue = temp
11
- }
12
-
13
- // 如果相等
14
- else if (maxValue == minValue) {
15
- return [maxValue]
16
- }
17
-
18
- // 为了变成 -100 ~ 100 需要放大或者缩小的倍数
19
- let times100 =
20
-
21
- (function (_value) {
22
-
23
- // 先确定基调,是放大还是缩小
24
- let _times100_base = (_value < 100 && _value > -100) ? 10 : 0.1
25
-
26
- // 记录当前缩放倍数
27
- let _times100 = -1, _tiemsValue = _value
28
-
29
- while (_times100_base == 10 ?
30
- // 如果是放大,超过 -100 ~ 100 就应该停止
31
- (_tiemsValue >= -100 && _tiemsValue <= 100)
32
- :
33
- // 如果是缩小,进入 -100 ~ 100 就应该停止
34
- (_tiemsValue <= -100 || _tiemsValue >= 100)
35
- ) {
36
-
37
- _times100 += 1
38
- _tiemsValue *= _times100_base
39
-
40
- }
41
-
42
- if (_times100_base == 10) {
43
- return Math.pow(10, _times100)
44
- } else {
45
-
46
- // 解决类似 0.1 * 0.1 = 0.010000000000000002 浮点运算不准确问题
47
- let temp = "0."
48
- for (let i = 1; i < _times100; i++) {
49
- temp += "0";
50
- }
51
- return +(temp + "1")
52
- }
53
- })
54
-
55
- // 根据差值来缩放
56
- (maxValue - minValue)
57
-
58
-
59
- // 求解出 -100 ~ 100 的最佳间距值 后直接转换原来的倍数
60
- let distance100 = Math.ceil((maxValue - minValue) * times100 / num)
61
-
62
- // 校对一下
63
- distance100 = {
64
- 3: 2,
65
- 4: 5,
66
- 6: 5,
67
- 7: 5,
68
- 8: 10,
69
- 9: 10,
70
- 11: 10,
71
- 12: 10,
72
- 13: 15,
73
- 14: 15,
74
- 16: 15,
75
- 17: 15,
76
- 18: 20,
77
- 19: 20,
78
- 21: 20,
79
- 22: 20,
80
- 23: 25,
81
- 24: 25,
82
- 26: 25,
83
- 27: 25
84
- }[distance100] || distance100
85
-
86
- let distance = distance100 / times100
87
-
88
- // 最小值,也就是起点
89
- let begin = Math.floor(minValue / distance) * distance
90
-
91
- let rulerArray = []
92
- // 获取最终的刻度尺数组
93
- rulerArray.push(begin)
94
- for (let index = 1; rulerArray[rulerArray.length - 1] < maxValue; index++) {
95
- rulerArray.push(begin + distance * index)
96
- }
97
-
98
- return rulerArray
99
- }
1
+ // 刻度尺刻度求解
2
+
3
+ // 需要注意的是,实际的间距个数可能是 num-1 或 num 或 num+1 或 1
4
+ export default function (maxValue: number, minValue: number, num: number) {
5
+
6
+ // 如果最大值最小值反了
7
+ if (maxValue < minValue) {
8
+ let temp = minValue
9
+ minValue = maxValue
10
+ maxValue = temp
11
+ }
12
+
13
+ // 如果相等
14
+ else if (maxValue == minValue) {
15
+ return [maxValue]
16
+ }
17
+
18
+ // 为了变成 -100 ~ 100 需要放大或者缩小的倍数
19
+ let times100 =
20
+
21
+ (function (_value) {
22
+
23
+ // 先确定基调,是放大还是缩小
24
+ let _times100_base = (_value < 100 && _value > -100) ? 10 : 0.1
25
+
26
+ // 记录当前缩放倍数
27
+ let _times100 = -1, _tiemsValue = _value
28
+
29
+ while (_times100_base == 10 ?
30
+ // 如果是放大,超过 -100 ~ 100 就应该停止
31
+ (_tiemsValue >= -100 && _tiemsValue <= 100)
32
+ :
33
+ // 如果是缩小,进入 -100 ~ 100 就应该停止
34
+ (_tiemsValue <= -100 || _tiemsValue >= 100)
35
+ ) {
36
+
37
+ _times100 += 1
38
+ _tiemsValue *= _times100_base
39
+
40
+ }
41
+
42
+ if (_times100_base == 10) {
43
+ return Math.pow(10, _times100)
44
+ } else {
45
+
46
+ // 解决类似 0.1 * 0.1 = 0.010000000000000002 浮点运算不准确问题
47
+ let temp = "0."
48
+ for (let i = 1; i < _times100; i++) {
49
+ temp += "0";
50
+ }
51
+ return +(temp + "1")
52
+ }
53
+ })
54
+
55
+ // 根据差值来缩放
56
+ (maxValue - minValue)
57
+
58
+
59
+ // 求解出 -100 ~ 100 的最佳间距值 后直接转换原来的倍数
60
+ let distance100 = Math.ceil((maxValue - minValue) * times100 / num)
61
+
62
+ // 校对一下
63
+ distance100 = {
64
+ 3: 2,
65
+ 4: 5,
66
+ 6: 5,
67
+ 7: 5,
68
+ 8: 10,
69
+ 9: 10,
70
+ 11: 10,
71
+ 12: 10,
72
+ 13: 15,
73
+ 14: 15,
74
+ 16: 15,
75
+ 17: 15,
76
+ 18: 20,
77
+ 19: 20,
78
+ 21: 20,
79
+ 22: 20,
80
+ 23: 25,
81
+ 24: 25,
82
+ 26: 25,
83
+ 27: 25
84
+ }[distance100] || distance100
85
+
86
+ let distance = distance100 / times100
87
+
88
+ // 最小值,也就是起点
89
+ let begin = Math.floor(minValue / distance) * distance
90
+
91
+ let rulerArray = []
92
+ // 获取最终的刻度尺数组
93
+ rulerArray.push(begin)
94
+ for (let index = 1; rulerArray[rulerArray.length - 1] < maxValue; index++) {
95
+ rulerArray.push(begin + distance * index)
96
+ }
97
+
98
+ return rulerArray
99
+ }
@@ -1,140 +1,140 @@
1
- import { callbackFun } from '../types/viewHandler'
2
-
3
- let mousePosition = (el: HTMLElement, event: any) => {
4
- let bounding = el.getBoundingClientRect()
5
- return {
6
- "x": event.clientX - bounding.left,
7
- "y": event.clientY - bounding.top
8
- }
9
- }
10
-
11
- let getKeyString = (event: any) => {
12
- return {
13
- 37: "left",
14
- 38: "up",
15
- 39: "right",
16
- 40: "down",
17
- }[event.keyCode || event.which]
18
- }
19
-
20
- export default function (callback: callbackFun) {
21
-
22
- let el = document.getElementsByTagName('body')[0]
23
-
24
- // 键盘控制
25
- el.addEventListener("keydown", function (event) {
26
- let keyCode = getKeyString(event)
27
-
28
- // 视角向上
29
- if (keyCode == 'up') {
30
- callback({
31
- type: "lookUp",
32
- normal: [],
33
- value: 0.1
34
- })
35
- }
36
-
37
- // 视角向下
38
- else if (keyCode == 'down') {
39
- callback({
40
- type: "lookDown",
41
- normal: [],
42
- value: 0.1
43
- })
44
- }
45
-
46
- // 视角向左
47
- else if (keyCode == 'left') {
48
- callback({
49
- type: "lookLeft",
50
- normal: [],
51
- value: 0.1
52
- })
53
- }
54
-
55
- // 视角向右
56
- else if (keyCode == 'right') {
57
- callback({
58
- type: "lookRight",
59
- normal: [],
60
- value: 0.1
61
- })
62
- }
63
-
64
- })
65
-
66
- // 鼠标控制
67
- let mouseP = null;
68
- let doMove = function (event) {
69
- if (mouseP == null) return
70
-
71
- let tempMouseP = mousePosition(el, event)
72
-
73
- // 先求解出轨迹向量
74
- let normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y]
75
-
76
- // 方向向量旋转90deg得到旋转向量
77
- let rotateNormal = [
78
- normal[1],
79
- normal[0],
80
- 0
81
- ]
82
-
83
- // 非法射线忽略
84
- if (rotateNormal[0] == 0 && rotateNormal[1] == 0) return
85
-
86
- callback({
87
- type: "rotate",
88
- normal: rotateNormal,
89
- value: (Math.abs(tempMouseP.x - mouseP.x) + Math.abs(tempMouseP.y - mouseP.y)) * 0.01
90
- })
91
-
92
- mouseP = tempMouseP
93
- }
94
-
95
- el.addEventListener("mousedown", (event) => {
96
- mouseP = mousePosition(el, event)
97
- })
98
- el.addEventListener("mouseup", (event) => {
99
- mouseP = null
100
- })
101
- el.addEventListener("mousemove", (event) => {
102
- doMove(event)
103
- })
104
-
105
- // 手指控制
106
- el.addEventListener("touchend", (event) => {
107
- mouseP = null;
108
- })
109
- el.addEventListener("touchstart", (event) => {
110
- mouseP = mousePosition(el, event)
111
- })
112
- el.addEventListener("touchmove", (event) => {
113
- doMove(event.touches[0])
114
- })
115
-
116
- let doScale = function (value: number) {
117
- if (value == 0) return
118
-
119
- let baseTimes = 0.899
120
- callback({
121
- type: "scale",
122
- value: value < 0 ? baseTimes : 2 - baseTimes,
123
- normal: []
124
- })
125
- }
126
-
127
- // 滚轮控制
128
- el.addEventListener("mousewheel", function (event: any) {
129
- doScale(event.wheelDelta)
130
- })
131
-
132
- if (window.addEventListener) {
133
-
134
- // 针对火狐浏览器
135
- window.addEventListener('DOMMouseScroll', function (event: any) {
136
- doScale(-1 * event.detail)
137
- }, false)
138
- }
139
-
1
+ import { callbackFun } from '../types/viewHandler'
2
+
3
+ let mousePosition = (el: HTMLElement, event: any) => {
4
+ let bounding = el.getBoundingClientRect()
5
+ return {
6
+ "x": event.clientX - bounding.left,
7
+ "y": event.clientY - bounding.top
8
+ }
9
+ }
10
+
11
+ let getKeyString = (event: any) => {
12
+ return {
13
+ 37: "left",
14
+ 38: "up",
15
+ 39: "right",
16
+ 40: "down",
17
+ }[event.keyCode || event.which]
18
+ }
19
+
20
+ export default function (callback: callbackFun) {
21
+
22
+ let el = document.getElementsByTagName('body')[0]
23
+
24
+ // 键盘控制
25
+ el.addEventListener("keydown", function (event) {
26
+ let keyCode = getKeyString(event)
27
+
28
+ // 视角向上
29
+ if (keyCode == 'up') {
30
+ callback({
31
+ type: "lookUp",
32
+ normal: [],
33
+ value: 0.1
34
+ })
35
+ }
36
+
37
+ // 视角向下
38
+ else if (keyCode == 'down') {
39
+ callback({
40
+ type: "lookDown",
41
+ normal: [],
42
+ value: 0.1
43
+ })
44
+ }
45
+
46
+ // 视角向左
47
+ else if (keyCode == 'left') {
48
+ callback({
49
+ type: "lookLeft",
50
+ normal: [],
51
+ value: 0.1
52
+ })
53
+ }
54
+
55
+ // 视角向右
56
+ else if (keyCode == 'right') {
57
+ callback({
58
+ type: "lookRight",
59
+ normal: [],
60
+ value: 0.1
61
+ })
62
+ }
63
+
64
+ })
65
+
66
+ // 鼠标控制
67
+ let mouseP = null;
68
+ let doMove = function (event) {
69
+ if (mouseP == null) return
70
+
71
+ let tempMouseP = mousePosition(el, event)
72
+
73
+ // 先求解出轨迹向量
74
+ let normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y]
75
+
76
+ // 方向向量旋转90deg得到旋转向量
77
+ let rotateNormal = [
78
+ normal[1],
79
+ normal[0],
80
+ 0
81
+ ]
82
+
83
+ // 非法射线忽略
84
+ if (rotateNormal[0] == 0 && rotateNormal[1] == 0) return
85
+
86
+ callback({
87
+ type: "rotate",
88
+ normal: rotateNormal,
89
+ value: (Math.abs(tempMouseP.x - mouseP.x) + Math.abs(tempMouseP.y - mouseP.y)) * 0.01
90
+ })
91
+
92
+ mouseP = tempMouseP
93
+ }
94
+
95
+ el.addEventListener("mousedown", (event) => {
96
+ mouseP = mousePosition(el, event)
97
+ })
98
+ el.addEventListener("mouseup", (event) => {
99
+ mouseP = null
100
+ })
101
+ el.addEventListener("mousemove", (event) => {
102
+ doMove(event)
103
+ })
104
+
105
+ // 手指控制
106
+ el.addEventListener("touchend", (event) => {
107
+ mouseP = null;
108
+ })
109
+ el.addEventListener("touchstart", (event) => {
110
+ mouseP = mousePosition(el, event)
111
+ })
112
+ el.addEventListener("touchmove", (event) => {
113
+ doMove(event.touches[0])
114
+ })
115
+
116
+ let doScale = function (value: number) {
117
+ if (value == 0) return
118
+
119
+ let baseTimes = 0.899
120
+ callback({
121
+ type: "scale",
122
+ value: value < 0 ? baseTimes : 2 - baseTimes,
123
+ normal: []
124
+ })
125
+ }
126
+
127
+ // 滚轮控制
128
+ el.addEventListener("mousewheel", function (event: any) {
129
+ doScale(event.wheelDelta)
130
+ })
131
+
132
+ if (window.addEventListener) {
133
+
134
+ // 针对火狐浏览器
135
+ window.addEventListener('DOMMouseScroll', function (event: any) {
136
+ doScale(-1 * event.detail)
137
+ }, false)
138
+ }
139
+
140
140
  }
package/types/Buffer.d.ts CHANGED
@@ -1,24 +1,24 @@
1
- export default interface BufferType {
2
-
3
- /**
4
- * 使用这个缓冲区对象
5
- * (先于写入和分配)
6
- */
7
- use(): this
8
-
9
- /**
10
- * 写入数据
11
- * @param data 具体的数据内容
12
- */
13
- write(data: Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array): this
14
-
15
- /**
16
- * 分配使用
17
- * @param location 变量位置
18
- * @param size 一个数据的长度
19
- * @param stride 一组数据的长度(可能包含多组)
20
- * @param offset 读取位置偏移
21
- */
22
- divide(location: number, size: number, stride: number, offset?: number): this
23
-
1
+ export default interface BufferType {
2
+
3
+ /**
4
+ * 使用这个缓冲区对象
5
+ * (先于写入和分配)
6
+ */
7
+ use(): this
8
+
9
+ /**
10
+ * 写入数据
11
+ * @param data 具体的数据内容
12
+ */
13
+ write(data: Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array): this
14
+
15
+ /**
16
+ * 分配使用
17
+ * @param location 变量位置
18
+ * @param size 一个数据的长度
19
+ * @param stride 一组数据的长度(可能包含多组)
20
+ * @param offset 读取位置偏移
21
+ */
22
+ divide(location: number, size: number, stride: number, offset?: number): this
23
+
24
24
  }