vislite 0.4.1-alpha.2 → 0.4.1-beta.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/.editorconfig +19 -0
- package/CHANGELOG +17 -8
- package/README.md +16 -1
- package/lib/Buffer/index.umd.js +2 -2
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +89 -10
- 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/OralCanvas/index.es.js +79 -8
- package/lib/OralCanvas/index.es.min.js +3 -3
- package/lib/OralWebGL/index.es.js +35 -10
- package/lib/OralWebGL/index.es.min.js +3 -3
- package/lib/SVG/index.umd.js +2 -2
- package/lib/SVG/index.umd.min.js +2 -2
- package/lib/Shader/index.umd.js +82 -3
- package/lib/Shader/index.umd.min.js +3 -3
- package/lib/Texture/index.umd.js +3 -5
- package/lib/Texture/index.umd.min.js +3 -3
- package/lib/TreeLayout/index.umd.js +427 -0
- package/lib/TreeLayout/index.umd.min.js +11 -0
- package/lib/WebGL/index.umd.js +45 -12
- package/lib/WebGL/index.umd.min.js +3 -3
- package/lib/animation/index.umd.js +3 -3
- package/lib/animation/index.umd.min.js +2 -2
- package/lib/formatColor/index.umd.js +59 -0
- package/lib/formatColor/index.umd.min.js +11 -0
- 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 +555 -23
- package/lib/index.umd.min.js +3 -3
- package/lib/resizeObserver/index.umd.js +48 -0
- package/lib/resizeObserver/index.umd.min.js +11 -0
- 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/throttle/index.umd.js +68 -0
- package/lib/throttle/index.umd.min.js +11 -0
- package/lib/viewHandler/index.umd.js +2 -2
- package/lib/viewHandler/index.umd.min.js +2 -2
- package/package/Buffer/index.ts +1 -0
- package/package/Canvas/index.ts +1 -0
- package/package/OralCanvas/index.ts +1 -0
- package/package/OralWebGL/index.ts +1 -0
- package/package/Shader/index.ts +39 -1
- package/package/Texture/index.ts +1 -0
- package/package/TreeLayout/index.ts +3 -0
- package/package/WebGL/index.ts +1 -0
- package/package/formatColor/index.ts +3 -0
- package/package/index.ts +12 -1
- package/package/resizeObserver/index.ts +3 -0
- package/package/throttle/index.ts +3 -0
- package/package.json +1 -1
- package/src/Canvas.ts +7 -3
- package/src/Eoap.ts +1 -1
- package/src/Matrix4/index.ts +1 -1
- package/src/Mercator.ts +1 -1
- package/src/SVG.ts +2 -1
- package/src/TreeLayout/index.ts +186 -0
- package/src/WebGL.ts +7 -3
- package/src/animation.ts +2 -3
- package/src/common/canvas/config.ts +2 -1
- package/src/common/canvas/index.ts +10 -3
- package/src/common/canvas/painter.ts +74 -5
- package/src/common/mergeOption.ts +7 -0
- package/src/common/svg/config.ts +2 -1
- package/src/common/svg/index.ts +2 -1
- package/src/common/svg/tool.ts +2 -1
- package/src/common/tree/index.ts +26 -0
- package/src/common/tree/toInnerTree.ts +57 -0
- package/src/common/tree/toPlainTree.ts +132 -0
- package/src/common/webgl/doDraw.ts +2 -0
- package/src/common/webgl/getShader.ts +25 -52
- package/src/common/webgl/index.ts +4 -3
- package/src/common/webgl/texture.ts +2 -5
- package/src/formatColor.ts +45 -0
- package/src/interpolation/Cardinal.ts +2 -1
- package/src/interpolation/Hermite.ts +1 -1
- package/src/resizeObserver.ts +37 -0
- package/src/ruler.ts +1 -1
- package/src/shader/fsColor.c +8 -0
- package/src/shader/fsColors.c +8 -0
- package/src/shader/fsCube.c +9 -0
- package/src/shader/fsImage.c +9 -0
- package/src/shader/vsColor.c +18 -0
- package/src/shader/vsColors.c +14 -0
- package/src/shader/vsCube.c +14 -0
- package/src/shader/vsImage.c +14 -0
- package/src/throttle.ts +50 -0
- package/src/viewHandler.ts +1 -1
- package/types/Canvas.d.ts +12 -0
- package/types/CanvasOption.d.ts +2 -2
- package/types/Shader.d.ts +6 -0
- package/types/Tree.d.ts +38 -0
- package/types/TreeConfig.d.ts +25 -0
- package/types/TreeLayout.d.ts +49 -0
- package/types/TreeOption.d.ts +46 -0
- package/types/formatColor.d.ts +3 -0
- package/types/index.d.ts +24 -1
- package/types/resizeObserver.d.ts +3 -0
- package/types/throttle.d.ts +5 -0
- package/types/throttleOption.d.ts +20 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type TreeConfigType from '../../../types/TreeConfig'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 根据配置的层次关系(配置的id,child,root)把原始数据变成内部结构,方便后期位置计算
|
|
5
|
+
*
|
|
6
|
+
* tempTree[id] = {
|
|
7
|
+
* "data": 原始数据,
|
|
8
|
+
* "pid": 父亲ID,
|
|
9
|
+
* "id": 唯一标识ID,
|
|
10
|
+
* "show": boolean,
|
|
11
|
+
* "isOpen": boolean,
|
|
12
|
+
* "children": [cid1、cid2、...]
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
export default (initTree: any, config: TreeConfigType) => {
|
|
16
|
+
let tempTree = {}
|
|
17
|
+
|
|
18
|
+
// 根结点
|
|
19
|
+
let temp = config.root(initTree), id: number | string, rid: number | string
|
|
20
|
+
id = rid = config.id(temp)
|
|
21
|
+
tempTree[id] = {
|
|
22
|
+
"data": temp,
|
|
23
|
+
"pid": null,
|
|
24
|
+
"id": id,
|
|
25
|
+
"isOpen": true,
|
|
26
|
+
"show": true,
|
|
27
|
+
"children": []
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let num: number = 1
|
|
31
|
+
|
|
32
|
+
// 根据传递的原始数据,生成内部统一结构
|
|
33
|
+
; (function createTree(pdata: any, pid: number | string) {
|
|
34
|
+
var children = config.children(pdata, initTree)
|
|
35
|
+
num += children ? children.length : 0
|
|
36
|
+
for (let flag = 0; children && flag < children.length; flag++) {
|
|
37
|
+
id = config.id(children[flag])
|
|
38
|
+
tempTree[pid].children.push(id);
|
|
39
|
+
tempTree[id] = {
|
|
40
|
+
"data": children[flag],
|
|
41
|
+
"pid": pid,
|
|
42
|
+
"id": id,
|
|
43
|
+
"isOpen": true,
|
|
44
|
+
"show": true,
|
|
45
|
+
"children": []
|
|
46
|
+
}
|
|
47
|
+
createTree(children[flag], id)
|
|
48
|
+
}
|
|
49
|
+
})(temp, id)
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
rid,
|
|
53
|
+
value: tempTree,
|
|
54
|
+
num
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type TreeConfigType from '../../../types/TreeConfig'
|
|
2
|
+
|
|
3
|
+
import toInnerTree from './toInnerTree'
|
|
4
|
+
|
|
5
|
+
// 可以传递任意格式的树原始数据
|
|
6
|
+
// 只要配置对应的解析方法即可
|
|
7
|
+
export default function (initTree: any, config: TreeConfigType, noOpens: {}) {
|
|
8
|
+
let treeData = toInnerTree(initTree, config)
|
|
9
|
+
|
|
10
|
+
let alltreedata = treeData.value // 维护的树
|
|
11
|
+
let rootid = treeData.rid // 根结点ID
|
|
12
|
+
|
|
13
|
+
if (treeData.num == 1) {
|
|
14
|
+
alltreedata[rootid].left = 0.5
|
|
15
|
+
alltreedata[rootid].top = 0.5
|
|
16
|
+
alltreedata[rootid].show = true
|
|
17
|
+
return {
|
|
18
|
+
deep: 1,
|
|
19
|
+
node: alltreedata,
|
|
20
|
+
root: rootid,
|
|
21
|
+
size: 1
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
|
|
25
|
+
let beforeDis = [], size = 0, maxDeep = 0
|
|
26
|
+
|
|
27
|
+
if (noOpens[rootid]) {
|
|
28
|
+
alltreedata[rootid].left = 0.5
|
|
29
|
+
alltreedata[rootid].top = 0.5
|
|
30
|
+
alltreedata[rootid].show = true
|
|
31
|
+
|
|
32
|
+
size = 1
|
|
33
|
+
} else {
|
|
34
|
+
; (function positionCalc(pNode, deep) {
|
|
35
|
+
|
|
36
|
+
if (deep > maxDeep) maxDeep = deep
|
|
37
|
+
|
|
38
|
+
let flag: number = 0
|
|
39
|
+
if (!noOpens[pNode.id]) {
|
|
40
|
+
|
|
41
|
+
for (flag = 0; flag < pNode.children.length; flag++)
|
|
42
|
+
|
|
43
|
+
// 因为全部的子结点的位置确定了,父结点的y位置就是子结点的中间位置
|
|
44
|
+
// 因此有子结点的,先计算子结点
|
|
45
|
+
positionCalc(alltreedata[pNode.children[flag]], deep + 1)
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// left的位置比较简单,deep从0开始编号
|
|
50
|
+
// 比如deep=0,第一层,left=0+0.5=0.5,也就是根结点
|
|
51
|
+
alltreedata[pNode.id].left = deep + 0.5
|
|
52
|
+
if (flag == 0) {
|
|
53
|
+
|
|
54
|
+
// beforeDis是一个数组,用以记录每一层此刻top下边缘(每一层是从上到下)
|
|
55
|
+
// 比如一层的第一个,top值最小可以取top=0.5
|
|
56
|
+
// 为了方便计算,beforeDis[deep] == undefined的时候表示现在准备计算的是这层的第一个结点
|
|
57
|
+
// 因此设置最低上边缘为-0.5
|
|
58
|
+
if (beforeDis[deep] == void 0) beforeDis[deep] = -0.5
|
|
59
|
+
// 父边缘同意的进行初始化
|
|
60
|
+
if (beforeDis[deep - 1] == void 0) beforeDis[deep - 1] = -0.5
|
|
61
|
+
|
|
62
|
+
// 添加的新结点top值第一种求法:本层上边缘+1(比如上边缘是-0.5,那么top最小是top=-0.5+1=0.5)
|
|
63
|
+
alltreedata[pNode.id].top = beforeDis[deep] + 1
|
|
64
|
+
|
|
65
|
+
let pTop = beforeDis[deep] + 1 + (alltreedata[pNode.pid].children.length - 1) * 0.5
|
|
66
|
+
// 计算的原则是:如果第一种可行,选择第一种,否则必须选择第二种
|
|
67
|
+
// 判断第一种是否可行的方法就是:如果第一种计算后确定的孩子上边缘不对导致孩子和孩子的前兄弟重合就是可行的
|
|
68
|
+
if (pTop - 1 < beforeDis[deep - 1])
|
|
69
|
+
// 必须保证父亲结点和父亲的前一个兄弟保存1的距离,至少
|
|
70
|
+
// 添加的新结点top值的第二种求法:根据孩子取孩子结点的中心top
|
|
71
|
+
alltreedata[pNode.id].top = beforeDis[deep - 1] + 1 - (alltreedata[pNode.pid].children.length - 1) * 0.5
|
|
72
|
+
|
|
73
|
+
} else {
|
|
74
|
+
|
|
75
|
+
// 此刻flag!=0
|
|
76
|
+
// 意味着结点有孩子,那么问题就解决了,直接取孩子的中间即可
|
|
77
|
+
// 其实,flag==0的分支计算的就是孩子,是没有孩子的叶结点,那是关键
|
|
78
|
+
alltreedata[pNode.id].top = (alltreedata[pNode.children[0]].top + alltreedata[pNode.children[flag - 1]].top) * 0.5
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 因为计算孩子的时候
|
|
82
|
+
// 无法掌握父辈兄弟的情况
|
|
83
|
+
// 可能会出现父亲和兄弟重叠问题
|
|
84
|
+
if (alltreedata[pNode.id].top <= beforeDis[deep]) {
|
|
85
|
+
let needUp = beforeDis[deep] + 1 - alltreedata[pNode.id].top
|
|
86
|
+
(function doUp(_pid: number | string, _deep: number) {
|
|
87
|
+
alltreedata[_pid].top += needUp;
|
|
88
|
+
if (beforeDis[_deep] < alltreedata[_pid].top) beforeDis[_deep] = alltreedata[_pid].top
|
|
89
|
+
|
|
90
|
+
for (let _flag = 0; _flag < alltreedata[_pid].children.length; _flag++) {
|
|
91
|
+
doUp(alltreedata[_pid].children[_flag], _deep + 1)
|
|
92
|
+
}
|
|
93
|
+
})(pNode.id, deep)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 计算好一个结点后,需要更新此刻该层的上边缘
|
|
97
|
+
beforeDis[deep] = alltreedata[pNode.id].top
|
|
98
|
+
|
|
99
|
+
// size在每次计算一个结点后更新,是为了最终绘图的时候知道树有多宽(此处应该叫高)
|
|
100
|
+
if (alltreedata[pNode.id].top + 0.5 > size) size = alltreedata[pNode.id].top + 0.5
|
|
101
|
+
|
|
102
|
+
})(alltreedata[rootid], 0)
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
// 对于不显示的,需要标记一下
|
|
106
|
+
for (let key in noOpens) {
|
|
107
|
+
if (noOpens[key]) {
|
|
108
|
+
alltreedata[key].isOpen = false
|
|
109
|
+
; (function updateHidden(pid, left, top) {
|
|
110
|
+
for (let index = 0; index < alltreedata[pid].children.length; index++) {
|
|
111
|
+
alltreedata[alltreedata[pid].children[index]].left = left
|
|
112
|
+
alltreedata[alltreedata[pid].children[index]].top = top
|
|
113
|
+
alltreedata[alltreedata[pid].children[index]].show = false
|
|
114
|
+
|
|
115
|
+
updateHidden(alltreedata[pid].children[index], left, top)
|
|
116
|
+
}
|
|
117
|
+
})(key, alltreedata[key].left, alltreedata[key].top)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 传递的参数分别表示:记录了位置信息的树结点集合、根结点ID和树的宽
|
|
122
|
+
return {
|
|
123
|
+
"node": alltreedata,
|
|
124
|
+
"root": rootid,
|
|
125
|
+
"size": size,
|
|
126
|
+
"deep": maxDeep + 1
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
}
|
|
@@ -60,6 +60,8 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
60
60
|
|
|
61
61
|
let size = (mesh.material.cube.right.image.value as any).width
|
|
62
62
|
|
|
63
|
+
painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0)
|
|
64
|
+
|
|
63
65
|
getTexture(type, painter, 'cube').useCube([
|
|
64
66
|
mesh.material.cube.right.image.value,
|
|
65
67
|
mesh.material.cube.left.image.value,
|
|
@@ -1,72 +1,45 @@
|
|
|
1
|
+
import type { meshType } from '../../../types/Object3D'
|
|
2
|
+
|
|
1
3
|
import ShaderObject from './shader'
|
|
2
4
|
|
|
3
|
-
import
|
|
5
|
+
import vsColor from '../../shader/vsColor.c'
|
|
6
|
+
import vsColors from '../../shader/vsColors.c'
|
|
7
|
+
import vsImage from '../../shader/vsImage.c'
|
|
8
|
+
import vsCube from '../../shader/vsCube.c'
|
|
9
|
+
|
|
10
|
+
import fsColor from '../../shader/fsColor.c'
|
|
11
|
+
import fsColors from '../../shader/fsColors.c'
|
|
12
|
+
import fsImage from '../../shader/fsImage.c'
|
|
13
|
+
import fsCube from '../../shader/fsCube.c'
|
|
4
14
|
|
|
5
15
|
let shaders = {}
|
|
6
16
|
export default function (type: string, painter: WebGLRenderingContext, mesh: meshType) {
|
|
7
17
|
|
|
8
18
|
let uniqueName = type +
|
|
9
|
-
(mesh.geometry.attributes.normal ? "1" : "0") +
|
|
10
|
-
(mesh.material.image ? "1" : "0") +
|
|
11
19
|
(mesh.material.color ? "1" : "0") +
|
|
12
20
|
(mesh.material.colors ? "1" : "0") +
|
|
21
|
+
(mesh.material.image ? "1" : "0") +
|
|
13
22
|
(mesh.material.cube ? "1" : "0")
|
|
14
23
|
if (shaders[uniqueName]) return shaders[uniqueName].use()
|
|
15
24
|
|
|
16
25
|
// 顶点着色器
|
|
17
|
-
let vertexShader =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
let vertexShader = {
|
|
27
|
+
[type + "1000"]: vsColor,
|
|
28
|
+
[type + "0100"]: vsColors,
|
|
29
|
+
[type + "0010"]: vsImage,
|
|
30
|
+
[type + "0001"]: vsCube
|
|
31
|
+
}[uniqueName].replace(/uniform +mat4 +u_matrix;/, `
|
|
22
32
|
uniform mat4 u_matrix_world;
|
|
23
33
|
uniform mat4 u_matrix_mesh;
|
|
24
|
-
uniform mat4 u_matrix_proporion
|
|
25
|
-
|
|
26
|
-
${mesh.material.image ? 'attribute vec2 a_textcoord;varying vec2 v_textcoord;' : ''}
|
|
27
|
-
|
|
28
|
-
${mesh.material.colors ? 'attribute vec4 a_color;varying vec4 v_color;' : ''}
|
|
29
|
-
|
|
30
|
-
void main(){
|
|
31
|
-
vec4 temp = a_position;
|
|
32
|
-
|
|
33
|
-
// 应用变换矩阵:屏幕比调平矩阵、世界矩阵、物体矩阵
|
|
34
|
-
temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * temp;
|
|
35
|
-
|
|
36
|
-
// 把原生的WebGL使用的左手坐标系变成了右手坐标系
|
|
37
|
-
temp.z = -1.0 * temp.z;
|
|
38
|
-
|
|
39
|
-
// 表示眼睛距离vec4(0.0,0.0,1.0)的距离
|
|
40
|
-
float dist = 4.0;
|
|
41
|
-
|
|
42
|
-
// 使用投影直接计算
|
|
43
|
-
// 为保证纹理和相对位置正确
|
|
44
|
-
// x、y、z的改变满足线性变换
|
|
45
|
-
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));
|
|
46
|
-
|
|
47
|
-
${mesh.geometry.attributes.normal ? 'v_normal = normalize(vec3(a_normal));' : ''}
|
|
48
|
-
${mesh.material.image ? 'v_textcoord = a_textcoord;' : ''}
|
|
49
|
-
${mesh.material.colors ? 'v_color=a_color;' : ''}
|
|
50
|
-
}
|
|
51
|
-
`
|
|
34
|
+
uniform mat4 u_matrix_proporion;`).replace(/u_matrix +\* +a_position/, "u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position")
|
|
52
35
|
|
|
53
36
|
// 片段(元)着色器
|
|
54
|
-
let fragmentShader =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
${mesh.material.image ? 'uniform sampler2D u_sampler;varying vec2 v_textcoord;' : ''}
|
|
61
|
-
${mesh.material.colors ? 'varying vec4 v_color;' : ''}
|
|
62
|
-
|
|
63
|
-
void main(){
|
|
64
|
-
${mesh.material.color ? 'gl_FragColor = u_color;' : ''}
|
|
65
|
-
${mesh.material.cube ? 'gl_FragColor = textureCube(u_texture,normalize(v_normal));' : ''}
|
|
66
|
-
${mesh.material.image ? 'gl_FragColor = texture2D(u_sampler,v_textcoord);' : ''}
|
|
67
|
-
${mesh.material.colors ? 'gl_FragColor=v_color;' : ''}
|
|
68
|
-
}
|
|
69
|
-
`
|
|
37
|
+
let fragmentShader = {
|
|
38
|
+
[type + "1000"]: fsColor,
|
|
39
|
+
[type + "0100"]: fsColors,
|
|
40
|
+
[type + "0010"]: fsImage,
|
|
41
|
+
[type + "0001"]: fsCube
|
|
42
|
+
}[uniqueName]
|
|
70
43
|
|
|
71
44
|
// 启用着色器
|
|
72
45
|
let shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use()
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type Object3DType from '../../../types/Object3D'
|
|
2
|
+
import type Scene3DType from '../../../types/Scene3D'
|
|
3
|
+
|
|
1
4
|
import getWebGLContext from './getWebGLContext'
|
|
2
|
-
import Object3DType from '../../../types/Object3D'
|
|
3
|
-
import Scene3DType from '../../../types/Scene3D'
|
|
4
5
|
import getColorFactory from './getColorFactory'
|
|
5
6
|
import Matrix4 from '../../Matrix4/index'
|
|
6
7
|
import doDraw from './doDraw'
|
|
@@ -186,7 +187,7 @@ class WebGL {
|
|
|
186
187
|
this.__regionName = regionName + ""
|
|
187
188
|
|
|
188
189
|
if (regionName) {
|
|
189
|
-
if (this.__regionList[regionName] ==
|
|
190
|
+
if (this.__regionList[regionName] == void 0) {
|
|
190
191
|
this.__regionList[regionName] = [... this.__regionAssemble(), 1]
|
|
191
192
|
}
|
|
192
193
|
this.__regionColor = this.__regionList[regionName]
|
|
@@ -7,11 +7,8 @@ let initTexture = (painter: WebGLRenderingContext, type: number, unit: number) =
|
|
|
7
7
|
// 创建纹理对象
|
|
8
8
|
let texture = painter.createTexture()
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// 开启纹理单元,unit表示开启的编号
|
|
13
|
-
painter.activeTexture(painter['TEXTURE' + unit])
|
|
14
|
-
}
|
|
10
|
+
// 开启纹理单元,unit表示开启的编号
|
|
11
|
+
painter.activeTexture(painter['TEXTURE' + unit])
|
|
15
12
|
|
|
16
13
|
// 绑定纹理对象到目标上
|
|
17
14
|
painter.bindTexture(type, texture)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
let toHex = (value: number) => {
|
|
2
|
+
let hex = value.toString(16)
|
|
3
|
+
return hex.length == 1 ? ("0" + hex) : hex
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export default function (color: string, format: string) {
|
|
7
|
+
|
|
8
|
+
let colorNode = document.getElementsByTagName('head')[0]
|
|
9
|
+
colorNode.style['color'] = color
|
|
10
|
+
|
|
11
|
+
// 获取结点的全部样式
|
|
12
|
+
let allStyle = document.defaultView && document.defaultView.getComputedStyle ?
|
|
13
|
+
document.defaultView.getComputedStyle(colorNode, null) :
|
|
14
|
+
(colorNode as any).currentStyle
|
|
15
|
+
|
|
16
|
+
let oralFormat = allStyle.getPropertyValue('color').replace(/rgba?\(/, '').replace(")", "").split(',')
|
|
17
|
+
for (let index = 0; index < oralFormat.length; index++) {
|
|
18
|
+
oralFormat[index] = +oralFormat[index]
|
|
19
|
+
}
|
|
20
|
+
oralFormat.push(1)
|
|
21
|
+
|
|
22
|
+
switch (format) {
|
|
23
|
+
case "3d": {
|
|
24
|
+
return [
|
|
25
|
+
oralFormat[0] / 255,
|
|
26
|
+
oralFormat[1] / 255,
|
|
27
|
+
oralFormat[2] / 255,
|
|
28
|
+
oralFormat[3]
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
case "rgba": {
|
|
32
|
+
return `rgba(${oralFormat[0]}, ${oralFormat[1]}, ${oralFormat[2]}, ${oralFormat[3]})`
|
|
33
|
+
}
|
|
34
|
+
case "rgb": {
|
|
35
|
+
return `rgb(${oralFormat[0]}, ${oralFormat[1]}, ${oralFormat[2]})`
|
|
36
|
+
}
|
|
37
|
+
case "hexAlpha": {
|
|
38
|
+
return `#${toHex(oralFormat[0])}${toHex(oralFormat[1])}${toHex(oralFormat[2])}${toHex(+(oralFormat[3] * 255).toFixed(0))}`
|
|
39
|
+
}
|
|
40
|
+
case "hex": {
|
|
41
|
+
return `#${toHex(oralFormat[0])}${toHex(oralFormat[1])}${toHex(oralFormat[2])}`
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
throw new Error("Unsupported color format: " + format)
|
|
45
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
let observer: ResizeObserver
|
|
2
|
+
|
|
3
|
+
let attrValueToCallback = {}, uniqueid = 0
|
|
4
|
+
|
|
5
|
+
export default function (el: HTMLElement | null, callback: Function) {
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
|
|
9
|
+
if (!observer) {
|
|
10
|
+
observer = new ResizeObserver(entries => {
|
|
11
|
+
for (const entry of entries) {
|
|
12
|
+
attrValueToCallback[(entry.target as any)._resize_observer_]()
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
uniqueid++
|
|
18
|
+
|
|
19
|
+
(el as any)._resize_observer_ = uniqueid
|
|
20
|
+
attrValueToCallback[uniqueid] = callback
|
|
21
|
+
|
|
22
|
+
observer.observe(el)
|
|
23
|
+
|
|
24
|
+
return function () {
|
|
25
|
+
if (observer) {
|
|
26
|
+
observer.unobserve(el)
|
|
27
|
+
delete attrValueToCallback[(el as any)._resize_observer_]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
} catch (e) {
|
|
32
|
+
callback()
|
|
33
|
+
|
|
34
|
+
// 如果浏览器不支持此接口
|
|
35
|
+
console.error('ResizeObserver undefined!')
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/ruler.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// 刻度尺刻度求解
|
|
2
2
|
|
|
3
|
-
import { rulerOptionType } from '../types/ruler'
|
|
3
|
+
import type { rulerOptionType } from '../types/ruler'
|
|
4
4
|
|
|
5
5
|
// 需要注意的是,实际的间距个数可能是 num-1 或 num 或 num+1 或 1
|
|
6
6
|
export default function (maxValue: number, minValue: number, num: number, option?: rulerOptionType) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
attribute vec4 a_position;
|
|
2
|
+
uniform mat4 u_matrix;
|
|
3
|
+
|
|
4
|
+
void main()
|
|
5
|
+
{
|
|
6
|
+
vec4 temp = u_matrix * a_position;
|
|
7
|
+
|
|
8
|
+
// 把原生的WebGL使用的左手坐标系变成了右手坐标系
|
|
9
|
+
temp.z = -1.0 * temp.z;
|
|
10
|
+
|
|
11
|
+
// 表示眼睛距离vec4(0.0,0.0,1.0)的距离
|
|
12
|
+
float dist = 4.0;
|
|
13
|
+
|
|
14
|
+
// 使用投影直接计算
|
|
15
|
+
// 为保证纹理和相对位置正确
|
|
16
|
+
// x、y、z的改变满足线性变换
|
|
17
|
+
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));
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
attribute vec4 a_position;
|
|
2
|
+
uniform mat4 u_matrix;
|
|
3
|
+
attribute vec4 a_color;
|
|
4
|
+
varying vec4 v_color;
|
|
5
|
+
|
|
6
|
+
void main()
|
|
7
|
+
{
|
|
8
|
+
vec4 temp = u_matrix * a_position;
|
|
9
|
+
temp.z = -1.0 * temp.z;
|
|
10
|
+
float dist = 4.0;
|
|
11
|
+
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));
|
|
12
|
+
|
|
13
|
+
v_color = a_color;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
attribute vec4 a_position;
|
|
2
|
+
uniform mat4 u_matrix;
|
|
3
|
+
attribute vec4 a_normal;
|
|
4
|
+
varying vec3 v_normal;
|
|
5
|
+
|
|
6
|
+
void main()
|
|
7
|
+
{
|
|
8
|
+
vec4 temp = u_matrix * a_position;
|
|
9
|
+
temp.z = -1.0 * temp.z;
|
|
10
|
+
float dist = 4.0;
|
|
11
|
+
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));
|
|
12
|
+
|
|
13
|
+
v_normal = normalize(vec3(a_normal));
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
attribute vec4 a_position;
|
|
2
|
+
uniform mat4 u_matrix;
|
|
3
|
+
attribute vec2 a_textcoord;
|
|
4
|
+
varying vec2 v_textcoord;
|
|
5
|
+
|
|
6
|
+
void main()
|
|
7
|
+
{
|
|
8
|
+
vec4 temp = u_matrix * a_position;
|
|
9
|
+
temp.z = -1.0 * temp.z;
|
|
10
|
+
float dist = 4.0;
|
|
11
|
+
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));
|
|
12
|
+
|
|
13
|
+
v_textcoord = a_textcoord;
|
|
14
|
+
}
|
package/src/throttle.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type throttleOptionType from '../types/throttleOption'
|
|
2
|
+
|
|
3
|
+
import mergeOption from './common/mergeOption'
|
|
4
|
+
|
|
5
|
+
export default function (callback: Function, option: throttleOptionType = {}) {
|
|
6
|
+
|
|
7
|
+
// 校对缺省值
|
|
8
|
+
option = mergeOption(option, {
|
|
9
|
+
time: 200,
|
|
10
|
+
keep: false,
|
|
11
|
+
opportunity: "end"
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
let hadInterval = false
|
|
15
|
+
let hadClick = false
|
|
16
|
+
let oneClick = false
|
|
17
|
+
|
|
18
|
+
return function () {
|
|
19
|
+
let _this = this, arg = arguments
|
|
20
|
+
|
|
21
|
+
// 如果前置任务都完成了
|
|
22
|
+
if (!hadInterval) {
|
|
23
|
+
if (option.opportunity != 'end') {
|
|
24
|
+
callback.apply(_this, arg)
|
|
25
|
+
}
|
|
26
|
+
hadInterval = true
|
|
27
|
+
|
|
28
|
+
let interval = setInterval(() => {
|
|
29
|
+
if (hadClick) {
|
|
30
|
+
if (!option.keep) {
|
|
31
|
+
callback.apply(_this, arg)
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
if (option.opportunity != 'begin') {
|
|
35
|
+
if (oneClick || option.opportunity == 'end') callback.apply(_this, arg)
|
|
36
|
+
}
|
|
37
|
+
hadInterval = false
|
|
38
|
+
oneClick = false
|
|
39
|
+
clearInterval(interval)
|
|
40
|
+
}
|
|
41
|
+
hadClick = false
|
|
42
|
+
}, option.time)
|
|
43
|
+
} else {
|
|
44
|
+
hadClick = true
|
|
45
|
+
oneClick = true
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
package/src/viewHandler.ts
CHANGED
package/types/Canvas.d.ts
CHANGED
|
@@ -236,6 +236,11 @@ export default interface CanvasType {
|
|
|
236
236
|
*/
|
|
237
237
|
clearRect(x: number, y: number, w: number, h: number): this
|
|
238
238
|
|
|
239
|
+
/**
|
|
240
|
+
* 是否绘制的内容只需要进行区域记录
|
|
241
|
+
*/
|
|
242
|
+
onlyRegion(flag: boolean): this
|
|
243
|
+
|
|
239
244
|
/**
|
|
240
245
|
* 设置区域
|
|
241
246
|
*/
|
|
@@ -285,4 +290,11 @@ export default interface CanvasType {
|
|
|
285
290
|
* @param y
|
|
286
291
|
*/
|
|
287
292
|
getColor(x: number, y: number): string
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* 渲染绘制(uniapp独有)
|
|
296
|
+
* @param reserve 是否保留当前画布上的内容
|
|
297
|
+
* @param callback 绘制完成后回调
|
|
298
|
+
*/
|
|
299
|
+
draw(reserve?: boolean, callback?: Function): void
|
|
288
300
|
}
|
package/types/CanvasOption.d.ts
CHANGED