vislite 0.6.0-alpha.0 → 0.6.0-alpha.2
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/.eslintrc.js +24 -0
- package/CHANGELOG +2 -0
- package/lib/Buffer/index.umd.js +2 -2
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +13 -8
- 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/Geometry/index.umd.js +7 -4
- package/lib/Geometry/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 +8 -6
- package/lib/OralCanvas/index.es.min.js +3 -3
- package/lib/OralWebGL/index.es.js +7 -5
- package/lib/OralWebGL/index.es.min.js +3 -3
- package/lib/SVG/index.umd.js +6 -4
- package/lib/SVG/index.umd.min.js +2 -2
- package/lib/Shader/index.umd.js +2 -2
- package/lib/Shader/index.umd.min.js +2 -2
- package/lib/Texture/index.umd.js +4 -3
- package/lib/Texture/index.umd.min.js +2 -2
- package/lib/TreeLayout/index.umd.js +8 -5
- package/lib/TreeLayout/index.umd.min.js +2 -2
- package/lib/WebGL/index.umd.js +7 -5
- package/lib/WebGL/index.umd.min.js +3 -3
- package/lib/animation/index.umd.js +4 -3
- package/lib/animation/index.umd.min.js +2 -2
- package/lib/formatColor/index.umd.js +2 -2
- package/lib/formatColor/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 +4 -3
- package/lib/getWebGLContext/index.umd.min.js +2 -2
- package/lib/index.umd.js +35 -20
- 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 +4 -3
- 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/lib/viewHandler/index.umd.js +4 -4
- package/lib/viewHandler/index.umd.min.js +3 -3
- package/package.json +6 -2
- package/src/Canvas.ts +8 -5
- package/src/Eoap.ts +6 -6
- package/src/Geometry.ts +5 -5
- package/src/Matrix4/index.ts +4 -4
- package/src/Matrix4/move.ts +1 -1
- package/src/Matrix4/rotate.ts +1 -1
- package/src/Matrix4/transform.ts +1 -1
- package/src/Mercator.ts +4 -4
- package/src/SVG.ts +2 -2
- package/src/WebGL.ts +3 -3
- package/src/animation.ts +6 -6
- package/src/common/assemble.ts +1 -1
- package/src/common/canvas/arc.ts +4 -3
- package/src/common/canvas/config.ts +5 -5
- package/src/common/canvas/gradient.ts +6 -6
- package/src/common/canvas/index.ts +13 -12
- package/src/common/canvas/painter.ts +5 -14
- package/src/common/geometry/prism-horizontal.ts +4 -2
- package/src/common/geometry/prism-vertical.ts +3 -3
- package/src/common/geometry/sphere-fragment.ts +5 -4
- package/src/common/geometry/tool/circle.ts +2 -2
- package/src/common/mergeOption.ts +1 -1
- package/src/common/setStyle.ts +1 -1
- package/src/common/svg/config.ts +11 -11
- package/src/common/svg/dictionary.ts +1 -1
- package/src/common/svg/gradient.ts +12 -12
- package/src/common/svg/index.ts +6 -6
- package/src/common/svg/tool.ts +2 -2
- package/src/common/tree/toInnerTree.ts +4 -3
- package/src/common/tree/toPlainTree.ts +8 -7
- package/src/common/webgl/buffer.ts +4 -4
- package/src/common/webgl/doDraw.ts +2 -2
- package/src/common/webgl/getColorFactory.ts +6 -6
- package/src/common/webgl/getShader.ts +5 -5
- package/src/common/webgl/getTexture.ts +2 -2
- package/src/common/webgl/getWebGLContext.ts +5 -4
- package/src/common/webgl/index.ts +11 -10
- package/src/common/webgl/shader.ts +6 -6
- package/src/common/webgl/texture.ts +7 -6
- package/src/formatColor.ts +5 -5
- package/src/getLoopColors.ts +1 -1
- package/src/interpolation/Cardinal.ts +1 -1
- package/src/interpolation/Hermite.ts +3 -3
- package/src/layout/TreeLayout.ts +21 -21
- package/src/move.ts +1 -1
- package/src/resizeObserver.ts +2 -1
- package/src/rotate.ts +1 -1
- package/src/ruler.ts +18 -18
- package/src/throttle.ts +3 -2
- package/src/viewHandler.ts +13 -13
- package/types/CanvasOption.d.ts +3 -2
- package/types/CanvasOpts.d.ts +10 -0
|
@@ -3,7 +3,7 @@ import rotate from '../../rotate'
|
|
|
3
3
|
// 棱柱垂直部分
|
|
4
4
|
|
|
5
5
|
export default function (normal: boolean, x: number, y: number, z: number, radius: number, height: number, num: number) {
|
|
6
|
-
|
|
6
|
+
const points = []
|
|
7
7
|
let beginPosition: [number, number]
|
|
8
8
|
|
|
9
9
|
if (num == 4) {
|
|
@@ -12,7 +12,7 @@ export default function (normal: boolean, x: number, y: number, z: number, radiu
|
|
|
12
12
|
beginPosition = [x + radius, z]
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
const deg = Math.PI * 2 / num, degHalf = Math.PI * 2 / (num * 2)
|
|
16
16
|
|
|
17
17
|
let endPosition: [number, number], normalPosition = []
|
|
18
18
|
for (let i = 0; i < num; i++) {
|
|
@@ -20,7 +20,7 @@ export default function (normal: boolean, x: number, y: number, z: number, radiu
|
|
|
20
20
|
endPosition = rotate(x, z, deg, ...beginPosition)
|
|
21
21
|
|
|
22
22
|
if (normal) {
|
|
23
|
-
|
|
23
|
+
const halfPosition = rotate(x, z, degHalf, ...beginPosition)
|
|
24
24
|
normalPosition = [halfPosition[0], 0, halfPosition[1]]
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -3,11 +3,12 @@ import rotate from '../../rotate'
|
|
|
3
3
|
// 球体中的一瓣子
|
|
4
4
|
|
|
5
5
|
export default function (normal: boolean, cx: number, cy: number, cz: number, radius: number, num: number, index: number) {
|
|
6
|
-
|
|
6
|
+
const points = [cx, cy + radius, cz], deg = Math.PI * 2 / num
|
|
7
|
+
let point: [number, number]
|
|
7
8
|
|
|
8
9
|
if (normal) points.push(0, radius, 0)
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
const copy2 = () => {
|
|
11
12
|
points.push(...points.slice(points.length - (normal ? 12 : 6)))
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -17,7 +18,7 @@ export default function (normal: boolean, cx: number, cy: number, cz: number, ra
|
|
|
17
18
|
if (i > 1) copy2()
|
|
18
19
|
|
|
19
20
|
// 第一个点
|
|
20
|
-
|
|
21
|
+
const point1 = rotate(cx, cz, deg * index, point[0], cz)
|
|
21
22
|
points.push(point1[0], point[1], point1[1])
|
|
22
23
|
|
|
23
24
|
if (normal) points.push(point1[0] - cx, point[1] - cy, point1[1] - cz)
|
|
@@ -25,7 +26,7 @@ export default function (normal: boolean, cx: number, cy: number, cz: number, ra
|
|
|
25
26
|
if (i > 1) copy2()
|
|
26
27
|
|
|
27
28
|
// 下一个点
|
|
28
|
-
|
|
29
|
+
const point2 = rotate(cx, cz, deg * (index + 1), point[0], cz)
|
|
29
30
|
points.push(point2[0], point[1], point2[1])
|
|
30
31
|
|
|
31
32
|
if (normal) points.push(point2[0] - cx, point2[1] - cy, point2[1] - cz)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// 计算切割份数
|
|
2
|
-
export
|
|
2
|
+
export const splitNum = function (precision: number, radius: number) {
|
|
3
3
|
|
|
4
4
|
// 根据切割弧度得出切割块数目
|
|
5
|
-
|
|
5
|
+
const num = Math.ceil(Math.PI * 2 /
|
|
6
6
|
|
|
7
7
|
// 为了满足最小精度而得出的切割弧度
|
|
8
8
|
Math.asin(precision / radius) * 2)
|
package/src/common/setStyle.ts
CHANGED
package/src/common/svg/config.ts
CHANGED
|
@@ -5,10 +5,10 @@ import setStyle from "../setStyle"
|
|
|
5
5
|
import arc from "../canvas/arc"
|
|
6
6
|
import { toNode } from "./tool"
|
|
7
7
|
|
|
8
|
-
export
|
|
9
|
-
|
|
8
|
+
export const initDefs = (el: SVGElement) => {
|
|
9
|
+
const defs = el.getElementsByTagName('defs')
|
|
10
10
|
if (defs.length <= 0) {
|
|
11
|
-
|
|
11
|
+
const newDefs = toNode("defs")
|
|
12
12
|
el.appendChild(newDefs)
|
|
13
13
|
return newDefs
|
|
14
14
|
} else {
|
|
@@ -17,7 +17,7 @@ export let initDefs = (el: SVGElement) => {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// 文字统一设置方法
|
|
20
|
-
export
|
|
20
|
+
export const initText = (
|
|
21
21
|
el: SVGElement,
|
|
22
22
|
config: SVGConfigType,
|
|
23
23
|
x: number,
|
|
@@ -63,7 +63,7 @@ export let initText = (
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// 画圆统一设置方法
|
|
66
|
-
export
|
|
66
|
+
export const initCircle = (el: SVGElement, cx: number, cy: number, r: number) => {
|
|
67
67
|
if (el.nodeName.toLowerCase() !== "circle")
|
|
68
68
|
throw new Error("Need a <circle> !")
|
|
69
69
|
setAttribute(el, "cx", cx)
|
|
@@ -72,13 +72,13 @@ export let initCircle = (el: SVGElement, cx: number, cy: number, r: number) => {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// 路径统一设置方法
|
|
75
|
-
export
|
|
75
|
+
export const initPath = (el: SVGElement, path: string) => {
|
|
76
76
|
if (el.nodeName.toLowerCase() !== "path") throw new Error("Need a <path> !")
|
|
77
77
|
setAttribute(el, "d", path)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
// 画矩形统一设置方法
|
|
81
|
-
export
|
|
81
|
+
export const initRect = (
|
|
82
82
|
el: SVGElement,
|
|
83
83
|
x: number,
|
|
84
84
|
y: number,
|
|
@@ -104,7 +104,7 @@ export let initRect = (
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
// 画弧统一设置方法
|
|
107
|
-
export
|
|
107
|
+
export const initArc = (
|
|
108
108
|
el: SVGElement,
|
|
109
109
|
config: SVGConfigType,
|
|
110
110
|
cx: number,
|
|
@@ -122,7 +122,7 @@ export let initArc = (
|
|
|
122
122
|
beginDeg = beginDeg % (Math.PI * 2)
|
|
123
123
|
|
|
124
124
|
if (r1 > r2) {
|
|
125
|
-
|
|
125
|
+
const temp = r1
|
|
126
126
|
r1 = r2
|
|
127
127
|
r2 = temp
|
|
128
128
|
}
|
|
@@ -154,8 +154,8 @@ export let initArc = (
|
|
|
154
154
|
endOuterY: number,
|
|
155
155
|
r: number
|
|
156
156
|
) {
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
const f = endA - beginA > Math.PI ? 1 : 0
|
|
158
|
+
let d = "M" + begInnerX + " " + begInnerY
|
|
159
159
|
if (r < 0) r = -r
|
|
160
160
|
|
|
161
161
|
d +=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const XLINK_ATTRIBUTE = ["href", "title", "show", "type", "role", "actuate"]
|
|
@@ -2,12 +2,12 @@ import { initDefs } from './config'
|
|
|
2
2
|
import { toNode, setAttribute } from "./tool"
|
|
3
3
|
|
|
4
4
|
// 线性渐变
|
|
5
|
-
export
|
|
5
|
+
export const linearGradient = function (el: SVGElement, x0: number, y0: number, x1: number, y1: number) {
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const defs = initDefs(el)
|
|
8
|
+
const gradientId = "vislite-lg-" + new Date().valueOf() + "-" + Math.random()
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
const linearGradient = toNode("linearGradient")
|
|
11
11
|
defs.appendChild(linearGradient)
|
|
12
12
|
setAttribute(linearGradient, "id", gradientId)
|
|
13
13
|
setAttribute(linearGradient, "x1", x0 + "%")
|
|
@@ -15,13 +15,13 @@ export let linearGradient = function (el: SVGElement, x0: number, y0: number, x1
|
|
|
15
15
|
setAttribute(linearGradient, "x2", x1 + "%")
|
|
16
16
|
setAttribute(linearGradient, "y2", y1 + "%")
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const enhanceGradient = {
|
|
19
19
|
"value": function () {
|
|
20
20
|
return "url(#" + gradientId + ")";
|
|
21
21
|
},
|
|
22
22
|
"setColor": function (stop: number, color: string) {
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
const stopEl = toNode("stop")
|
|
25
25
|
linearGradient.appendChild(stopEl)
|
|
26
26
|
setAttribute(stopEl, "offset", (stop * 100) + "%")
|
|
27
27
|
setAttribute(stopEl, "style", "stop-color:" + color + ";")
|
|
@@ -33,25 +33,25 @@ export let linearGradient = function (el: SVGElement, x0: number, y0: number, x1
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// 环形渐变
|
|
36
|
-
export
|
|
36
|
+
export const radialGradient = function (el: SVGElement, cx: number, cy: number, r: number) {
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const defs = initDefs(el)
|
|
39
|
+
const gradientId = "vislite-rg-" + new Date().valueOf() + "-" + Math.random()
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
const radialGradient = toNode("radialGradient")
|
|
42
42
|
defs.appendChild(radialGradient)
|
|
43
43
|
setAttribute(radialGradient, "id", gradientId)
|
|
44
44
|
setAttribute(radialGradient, "cx", cx + "%")
|
|
45
45
|
setAttribute(radialGradient, "cy", cy + "%")
|
|
46
46
|
setAttribute(radialGradient, "r", r + "%")
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
const enhanceGradient = {
|
|
49
49
|
"value": function () {
|
|
50
50
|
return "url(#" + gradientId + ")";
|
|
51
51
|
},
|
|
52
52
|
"setColor": function (stop: number, color: string) {
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
const stopEl = toNode("stop")
|
|
55
55
|
radialGradient.appendChild(stopEl)
|
|
56
56
|
setAttribute(stopEl, "offset", (stop * 100) + "%")
|
|
57
57
|
setAttribute(stopEl, "style", "stop-color:" + color + ";")
|
package/src/common/svg/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import rotate from "../../rotate"
|
|
|
7
7
|
import { linearGradient, radialGradient } from "./gradient"
|
|
8
8
|
|
|
9
9
|
// 属性名向下兼容
|
|
10
|
-
|
|
10
|
+
const oldAttrName = {
|
|
11
11
|
"font-size": "fontSize",
|
|
12
12
|
"font-family": "fontFamily",
|
|
13
13
|
"arc-start-cap": "arcStartCap",
|
|
@@ -57,8 +57,8 @@ class SVG {
|
|
|
57
57
|
if (typeof params !== "object") {
|
|
58
58
|
return this.__config[oldAttrName[params] || params]
|
|
59
59
|
} else {
|
|
60
|
-
for (
|
|
61
|
-
|
|
60
|
+
for (const key in params) {
|
|
61
|
+
const _key = oldAttrName[key] || key
|
|
62
62
|
this.__config[_key] = params[key]
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -136,7 +136,7 @@ class SVG {
|
|
|
136
136
|
if (typeof params !== "object") {
|
|
137
137
|
return getAttribute(this.__useEl, params)
|
|
138
138
|
} else {
|
|
139
|
-
for (
|
|
139
|
+
for (const key in params) {
|
|
140
140
|
setAttribute(this.__useEl, key, params[key])
|
|
141
141
|
}
|
|
142
142
|
return this
|
|
@@ -280,8 +280,8 @@ class SVG {
|
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
arc(x: number, y: number, r: number, beginDeg: number, deg: number) {
|
|
283
|
-
|
|
284
|
-
|
|
283
|
+
const begPosition = rotate(x, y, (beginDeg / 180) * Math.PI, x + r, y)
|
|
284
|
+
const endPosition = rotate(
|
|
285
285
|
x,
|
|
286
286
|
y,
|
|
287
287
|
((beginDeg + deg) / 180) * Math.PI,
|
package/src/common/svg/tool.ts
CHANGED
|
@@ -8,7 +8,7 @@ export function toNode(tagname: string) {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
// 设置属性
|
|
11
|
-
|
|
11
|
+
const _setAttribute = function (el: SVGElement, key: string, value: string | number) {
|
|
12
12
|
|
|
13
13
|
// 需要使用xlink命名空间的xml属性
|
|
14
14
|
if (XLINK_ATTRIBUTE.indexOf(key) > -1) {
|
|
@@ -20,7 +20,7 @@ let _setAttribute = function (el: SVGElement, key: string, value: string | numbe
|
|
|
20
20
|
el.setAttribute(key, value + "")
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
export
|
|
23
|
+
export const setAttribute = _setAttribute
|
|
24
24
|
|
|
25
25
|
// 获取属性
|
|
26
26
|
export function getAttribute(el: SVGElement, key: string) {
|
|
@@ -13,10 +13,11 @@ import type TreeConfigType from '../../../types/TreeConfig'
|
|
|
13
13
|
* }
|
|
14
14
|
*/
|
|
15
15
|
export default (initTree: any, config: TreeConfigType) => {
|
|
16
|
-
|
|
16
|
+
const tempTree = {}
|
|
17
17
|
|
|
18
18
|
// 根结点
|
|
19
|
-
|
|
19
|
+
const temp = config.root(initTree)
|
|
20
|
+
let id: number | string, rid: number | string
|
|
20
21
|
id = rid = config.id(temp)
|
|
21
22
|
tempTree[id] = {
|
|
22
23
|
"data": temp,
|
|
@@ -31,7 +32,7 @@ export default (initTree: any, config: TreeConfigType) => {
|
|
|
31
32
|
|
|
32
33
|
// 根据传递的原始数据,生成内部统一结构
|
|
33
34
|
; (function createTree(pdata: any, pid: number | string) {
|
|
34
|
-
|
|
35
|
+
const children = config.children(pdata, initTree)
|
|
35
36
|
num += children ? children.length : 0
|
|
36
37
|
for (let flag = 0; children && flag < children.length; flag++) {
|
|
37
38
|
id = config.id(children[flag])
|
|
@@ -5,10 +5,10 @@ import toInnerTree from './toInnerTree'
|
|
|
5
5
|
// 可以传递任意格式的树原始数据
|
|
6
6
|
// 只要配置对应的解析方法即可
|
|
7
7
|
export default function (initTree: any, config: TreeConfigType, noOpens: {}) {
|
|
8
|
-
|
|
8
|
+
const treeData = toInnerTree(initTree, config)
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const alltreedata = treeData.value // 维护的树
|
|
11
|
+
const rootid = treeData.rid // 根结点ID
|
|
12
12
|
|
|
13
13
|
if (treeData.num == 1) {
|
|
14
14
|
alltreedata[rootid].left = 0.5
|
|
@@ -22,7 +22,8 @@ export default function (initTree: any, config: TreeConfigType, noOpens: {}) {
|
|
|
22
22
|
}
|
|
23
23
|
} else {
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const beforeDis = []
|
|
26
|
+
let size = 0, maxDeep = 0
|
|
26
27
|
|
|
27
28
|
if (noOpens[rootid]) {
|
|
28
29
|
alltreedata[rootid].left = 0.5
|
|
@@ -62,7 +63,7 @@ export default function (initTree: any, config: TreeConfigType, noOpens: {}) {
|
|
|
62
63
|
// 添加的新结点top值第一种求法:本层上边缘+1(比如上边缘是-0.5,那么top最小是top=-0.5+1=0.5)
|
|
63
64
|
alltreedata[pNode.id].top = beforeDis[deep] + 1
|
|
64
65
|
|
|
65
|
-
|
|
66
|
+
const pTop = beforeDis[deep] + 1 + (alltreedata[pNode.pid].children.length - 1) * 0.5
|
|
66
67
|
// 计算的原则是:如果第一种可行,选择第一种,否则必须选择第二种
|
|
67
68
|
// 判断第一种是否可行的方法就是:如果第一种计算后确定的孩子上边缘不对导致孩子和孩子的前兄弟重合就是可行的
|
|
68
69
|
if (pTop - 1 < beforeDis[deep - 1])
|
|
@@ -82,7 +83,7 @@ export default function (initTree: any, config: TreeConfigType, noOpens: {}) {
|
|
|
82
83
|
// 无法掌握父辈兄弟的情况
|
|
83
84
|
// 可能会出现父亲和兄弟重叠问题
|
|
84
85
|
if (alltreedata[pNode.id].top <= beforeDis[deep]) {
|
|
85
|
-
|
|
86
|
+
const needUp = beforeDis[deep] + 1 - alltreedata[pNode.id].top
|
|
86
87
|
(function doUp(_pid: number | string, _deep: number) {
|
|
87
88
|
alltreedata[_pid].top += needUp;
|
|
88
89
|
if (beforeDis[_deep] < alltreedata[_pid].top) beforeDis[_deep] = alltreedata[_pid].top
|
|
@@ -103,7 +104,7 @@ export default function (initTree: any, config: TreeConfigType, noOpens: {}) {
|
|
|
103
104
|
|
|
104
105
|
}
|
|
105
106
|
// 对于不显示的,需要标记一下
|
|
106
|
-
for (
|
|
107
|
+
for (const key in noOpens) {
|
|
107
108
|
if (noOpens[key]) {
|
|
108
109
|
alltreedata[key].isOpen = false
|
|
109
110
|
; (function updateHidden(pid, left, top) {
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
// 获取一个新的缓冲区
|
|
6
6
|
// isElement默认false,创建第一种缓冲区,为true创建第二种
|
|
7
|
-
|
|
7
|
+
const newBuffer = (painter: WebGLRenderingContext) => {
|
|
8
8
|
return painter.createBuffer()
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
// 数据写入缓冲区
|
|
12
12
|
// data是一个类型化数组,表示写入的数据
|
|
13
13
|
// usage表示程序如何使用存储在缓冲区的数据
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const writeBuffer = (painter: WebGLRenderingContext, data: ArrayBuffer, isElement: boolean, usage: number) => {
|
|
15
|
+
const TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER
|
|
16
16
|
painter.bufferData(TYPE, data, usage)
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -29,7 +29,7 @@ let writeBuffer = (painter: WebGLRenderingContext, data: ArrayBuffer, isElement:
|
|
|
29
29
|
// stride相邻两个数据项的字节数
|
|
30
30
|
// offset数据的起点字节位置
|
|
31
31
|
// normalized是否把非浮点型的数据归一化到[0,1]或[-1,1]区间
|
|
32
|
-
|
|
32
|
+
const useBuffer = (painter: WebGLRenderingContext, location: number, size: number, type: number, stride: number, offset: number, normalized: boolean) => {
|
|
33
33
|
|
|
34
34
|
// 把缓冲区对象分配给目标变量
|
|
35
35
|
painter.vertexAttribPointer(location, size, type, normalized, stride, offset)
|
|
@@ -15,7 +15,7 @@ interface GlobalWorldType {
|
|
|
15
15
|
import { meshType } from '../../../types/Object3D'
|
|
16
16
|
|
|
17
17
|
export default function (type: string, painter: WebGLRenderingContext, mesh: meshType, meshWorld: MeshWorldType, globalWorld: GlobalWorldType) {
|
|
18
|
-
|
|
18
|
+
const shader = getShader(type, painter, mesh)
|
|
19
19
|
|
|
20
20
|
// 点数据写入缓冲区
|
|
21
21
|
new BufferObject(painter).use()
|
|
@@ -58,7 +58,7 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
58
58
|
// 立方纹理
|
|
59
59
|
else if ("cube" in mesh.material) {
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
const size = (mesh.material.cube.right.image.value as any).width
|
|
62
62
|
|
|
63
63
|
painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0)
|
|
64
64
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default function (painter: WebGLRenderingContext) {
|
|
2
|
-
|
|
2
|
+
const width = painter.drawingBufferWidth, height = painter.drawingBufferHeight
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const pixels = new Uint8Array(
|
|
5
5
|
4 * width * height
|
|
6
6
|
)
|
|
7
7
|
painter.readPixels(
|
|
@@ -17,10 +17,10 @@ export default function (painter: WebGLRenderingContext) {
|
|
|
17
17
|
return function (x: number, y: number): string {
|
|
18
18
|
y = height - y
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const pixelR = pixels[4 * (y * width + x)]
|
|
21
|
+
const pixelG = pixels[4 * (y * width + x) + 1]
|
|
22
|
+
const pixelB = pixels[4 * (y * width + x) + 2]
|
|
23
|
+
const pixelA = pixels[4 * (y * width + x) + 3]
|
|
24
24
|
|
|
25
25
|
return "rgba(" + pixelR + "," + pixelG + "," + pixelB + "," + pixelA + ")"
|
|
26
26
|
}
|
|
@@ -12,10 +12,10 @@ import fsColors from '../../shader/fsColors.c'
|
|
|
12
12
|
import fsImage from '../../shader/fsImage.c'
|
|
13
13
|
import fsCube from '../../shader/fsCube.c'
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
const shaders = {}
|
|
16
16
|
export default function (type: string, painter: WebGLRenderingContext, mesh: meshType) {
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const uniqueName = type +
|
|
19
19
|
(mesh.material.color ? "1" : "0") +
|
|
20
20
|
(mesh.material.colors ? "1" : "0") +
|
|
21
21
|
(mesh.material.image ? "1" : "0") +
|
|
@@ -23,7 +23,7 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
23
23
|
if (shaders[uniqueName]) return shaders[uniqueName].use()
|
|
24
24
|
|
|
25
25
|
// 顶点着色器
|
|
26
|
-
|
|
26
|
+
const vertexShader = {
|
|
27
27
|
[type + "1000"]: vsColor,
|
|
28
28
|
[type + "0100"]: vsColors,
|
|
29
29
|
[type + "0010"]: vsImage,
|
|
@@ -34,7 +34,7 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
34
34
|
uniform mat4 u_matrix_proporion;`).replace(/u_matrix +\* +a_position/, "u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position")
|
|
35
35
|
|
|
36
36
|
// 片段(元)着色器
|
|
37
|
-
|
|
37
|
+
const fragmentShader = {
|
|
38
38
|
[type + "1000"]: fsColor,
|
|
39
39
|
[type + "0100"]: fsColors,
|
|
40
40
|
[type + "0010"]: fsImage,
|
|
@@ -42,7 +42,7 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
42
42
|
}[uniqueName]
|
|
43
43
|
|
|
44
44
|
// 启用着色器
|
|
45
|
-
|
|
45
|
+
const shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use()
|
|
46
46
|
|
|
47
47
|
shaders[uniqueName] = shader
|
|
48
48
|
return shader
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import TextureObject from './texture'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const textures = {}
|
|
4
4
|
export default function (type: string, painter: WebGLRenderingContext, kind: string) {
|
|
5
|
-
|
|
5
|
+
const uniqueName = type + "-" + kind
|
|
6
6
|
|
|
7
7
|
if (!textures[uniqueName]) {
|
|
8
8
|
textures[uniqueName] = new TextureObject(painter, kind)
|
|
@@ -2,7 +2,8 @@ interface OptsType {
|
|
|
2
2
|
preserveDrawingBuffer?: boolean
|
|
3
3
|
}
|
|
4
4
|
export default function (canvas: HTMLCanvasElement, scale: number, opts: OptsType = {}) {
|
|
5
|
-
|
|
5
|
+
const names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"]
|
|
6
|
+
let painter = null
|
|
6
7
|
for (let i = 0; i < names.length; i++) {
|
|
7
8
|
try {
|
|
8
9
|
painter = canvas.getContext(names[i], opts)
|
|
@@ -11,10 +12,10 @@ export default function (canvas: HTMLCanvasElement, scale: number, opts: OptsTyp
|
|
|
11
12
|
}
|
|
12
13
|
if (!painter) throw new Error('Non canvas or browser does not support webgl.')
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
const width = painter.canvas.width, height = painter.canvas.height
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const viewWidth = width * scale
|
|
18
|
+
const viewHeight = height * scale
|
|
18
19
|
|
|
19
20
|
painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight)
|
|
20
21
|
|
|
@@ -10,7 +10,7 @@ import assemble from '../assemble'
|
|
|
10
10
|
// 获取区域信息前是否需要刷新区域
|
|
11
11
|
let needUpdate = false
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const scale = 10
|
|
14
14
|
class WebGL {
|
|
15
15
|
|
|
16
16
|
readonly name: string = "WebGL"
|
|
@@ -18,6 +18,7 @@ class WebGL {
|
|
|
18
18
|
painter: WebGLRenderingContext
|
|
19
19
|
private __regionPainter: WebGLRenderingContext
|
|
20
20
|
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
22
|
private __getColor = (x: number, y: number) => "rgba(0,0,0,1)"
|
|
22
23
|
|
|
23
24
|
private __regionList = {} //区域映射表
|
|
@@ -54,7 +55,7 @@ class WebGL {
|
|
|
54
55
|
})
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
const proportion = this.painter.canvas.width / this.painter.canvas.height
|
|
58
59
|
|
|
59
60
|
let xProportion = 1
|
|
60
61
|
let yProportion = 1
|
|
@@ -65,7 +66,7 @@ class WebGL {
|
|
|
65
66
|
yProportion = proportion
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
const zProportion = Math.min(xProportion, yProportion)
|
|
69
70
|
|
|
70
71
|
this.__proporion = [
|
|
71
72
|
xProportion, 0, 0, 0,
|
|
@@ -109,11 +110,11 @@ class WebGL {
|
|
|
109
110
|
private draw(object3D: Object3DType, isUpdateRegion = false) {
|
|
110
111
|
if (!isUpdateRegion) needUpdate = true
|
|
111
112
|
|
|
112
|
-
|
|
113
|
+
const meshWorld = {
|
|
113
114
|
matrix: object3D.matrix.value()
|
|
114
115
|
}
|
|
115
116
|
|
|
116
|
-
|
|
117
|
+
const globalWorld = {
|
|
117
118
|
matrix: this.__scene.matrix.value(),
|
|
118
119
|
proporion: this.__proporion
|
|
119
120
|
}
|
|
@@ -154,7 +155,7 @@ class WebGL {
|
|
|
154
155
|
|
|
155
156
|
// 对数据进行校对
|
|
156
157
|
for (let index = 0; index < object3D.mesh.length; index++) {
|
|
157
|
-
|
|
158
|
+
const mesh = object3D.mesh[index]
|
|
158
159
|
|
|
159
160
|
if (mesh.geometry.attributes.normal && Array.isArray(mesh.geometry.attributes.normal.array)) {
|
|
160
161
|
mesh.geometry.attributes.normal.array = new Float32Array(mesh.geometry.attributes.normal.array)
|
|
@@ -202,13 +203,13 @@ class WebGL {
|
|
|
202
203
|
if (needUpdate) this.review(true)
|
|
203
204
|
|
|
204
205
|
needUpdate = false
|
|
205
|
-
return new Promise((resolve
|
|
206
|
+
return new Promise((resolve) => {
|
|
206
207
|
|
|
207
|
-
|
|
208
|
+
const rgba = this.__getColor(x, y)
|
|
208
209
|
|
|
209
210
|
// 查找当前点击的区域
|
|
210
|
-
for (
|
|
211
|
-
|
|
211
|
+
for (const key in this.__regionList) {
|
|
212
|
+
const currentRGBA = this.__regionList[key]
|
|
212
213
|
if ("rgba(" + currentRGBA[0] * 255 + "," + currentRGBA[1] * 255 + "," + currentRGBA[2] * 255 + "," + currentRGBA[3] * 255 + ")" == rgba) {
|
|
213
214
|
resolve(key)
|
|
214
215
|
break
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
// 着色器采用的语言是:GLSL ES语言
|
|
6
6
|
|
|
7
7
|
// 把着色器字符串加载成着色器对象
|
|
8
|
-
|
|
8
|
+
const loadShader = (painter: WebGLRenderingContext, type: number, source: string) => {
|
|
9
9
|
|
|
10
10
|
// 创建着色器对象
|
|
11
|
-
|
|
11
|
+
const shader = painter.createShader(type)
|
|
12
12
|
if (shader == null) throw new Error('Unable to create shader!')
|
|
13
13
|
|
|
14
14
|
// 绑定资源
|
|
@@ -25,14 +25,14 @@ let loadShader = (painter: WebGLRenderingContext, type: number, source: string)
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// 建立着色器
|
|
28
|
-
|
|
28
|
+
const useShader = (painter: WebGLRenderingContext, vshaderSource: string, fshaderSource: string) => {
|
|
29
29
|
|
|
30
30
|
// 分别加载顶点着色器对象和片段着色器对象
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource)
|
|
32
|
+
const fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource)
|
|
33
33
|
|
|
34
34
|
// 创建一个着色器程序
|
|
35
|
-
|
|
35
|
+
const glProgram = painter.createProgram()
|
|
36
36
|
|
|
37
37
|
// 把前面创建的两个着色器对象添加到着色器程序中
|
|
38
38
|
painter.attachShader(glProgram, vertexShader)
|