vislite 0.6.0 → 0.7.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/CHANGELOG +15 -1
- package/README.md +24 -5
- package/lib/Buffer/index.umd.js +2 -2
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +4 -4
- 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 +69 -8
- package/lib/Geometry/index.umd.min.js +3 -3
- 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 +3 -3
- package/lib/OralCanvas/index.es.min.js +3 -3
- package/lib/OralWebGL/index.es.js +21 -18
- 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 +3 -2
- package/lib/Shader/index.umd.min.js +3 -3
- package/lib/Texture/index.umd.js +2 -2
- package/lib/Texture/index.umd.min.js +2 -2
- package/lib/TreeLayout/index.umd.js +13 -11
- package/lib/TreeLayout/index.umd.min.js +3 -3
- package/lib/WebGL/index.umd.js +22 -19
- package/lib/WebGL/index.umd.min.js +3 -3
- package/lib/animation/index.umd.js +2 -2
- 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 -4
- package/lib/getWebGLContext/index.umd.min.js +3 -3
- package/lib/index.umd.js +104 -38
- package/lib/index.umd.min.js +3 -3
- package/lib/move/index.umd.js +2 -2
- package/lib/move/index.umd.min.js +2 -2
- package/lib/resizeObserver/index.umd.js +2 -2
- package/lib/resizeObserver/index.umd.min.js +2 -2
- package/lib/rotate/index.umd.js +2 -2
- package/lib/rotate/index.umd.min.js +2 -2
- package/lib/ruler/index.umd.js +4 -4
- package/lib/ruler/index.umd.min.js +3 -3
- 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 +2 -2
- package/lib/viewHandler/index.umd.min.js +2 -2
- package/package/TreeLayout/index.ts +2 -2
- package/package.json +1 -1
- package/src/Canvas.ts +1 -1
- package/src/Eoap.ts +66 -66
- package/src/Geometry.ts +57 -13
- package/src/Matrix4/index.ts +84 -84
- package/src/Matrix4/move.ts +12 -12
- package/src/Matrix4/rotate.ts +1 -1
- package/src/Matrix4/transform.ts +1 -1
- package/src/Mercator.ts +27 -27
- package/src/SVG.ts +24 -24
- package/src/WebGL.ts +1 -1
- package/src/animation.ts +98 -98
- package/src/common/assemble.ts +1 -1
- package/src/common/canvas/arc.ts +51 -51
- package/src/common/canvas/config.ts +158 -158
- package/src/common/canvas/gradient.ts +29 -29
- package/src/common/canvas/index.ts +2 -2
- package/src/common/canvas/painter.ts +2 -0
- package/src/common/geometry/prism-horizontal.ts +35 -35
- package/src/common/geometry/prism-vertical.ts +1 -1
- package/src/common/geometry/sphere-fragment.ts +40 -40
- package/src/common/geometry/tool/circle.ts +11 -11
- package/src/common/geometry/tool/rotateLine.ts +36 -0
- package/src/common/mergeOption.ts +6 -6
- package/src/common/setStyle.ts +1 -1
- package/src/common/svg/config.ts +10 -6
- package/src/common/svg/gradient.ts +63 -63
- package/src/common/svg/index.ts +5 -5
- package/src/common/svg/tool.ts +6 -6
- package/src/common/tree/toInnerTree.ts +8 -6
- package/src/common/tree/toPlainTree.ts +1 -1
- package/src/common/webgl/buffer.ts +1 -1
- package/src/common/webgl/doDraw.ts +16 -16
- package/src/common/webgl/getColorFactory.ts +26 -26
- package/src/common/webgl/getShader.ts +48 -48
- package/src/common/webgl/getTexture.ts +11 -11
- package/src/common/webgl/getWebGLContext.ts +3 -3
- package/src/common/webgl/index.ts +6 -4
- package/src/common/webgl/shader.ts +3 -3
- package/src/common/webgl/texture.ts +2 -2
- package/src/formatColor.ts +44 -44
- package/src/getLoopColors.ts +42 -42
- package/src/interpolation/Cardinal.ts +110 -110
- package/src/interpolation/Hermite.ts +65 -65
- package/src/layout/TreeLayout.ts +13 -11
- package/src/move.ts +7 -7
- package/src/resizeObserver.ts +2 -2
- package/src/rotate.ts +7 -7
- package/src/ruler.ts +10 -10
- package/src/throttle.ts +52 -52
- package/src/viewHandler.ts +4 -2
- package/types/Canvas.d.ts +1 -1
- package/types/CanvasOption.d.ts +8 -8
- package/types/CanvasOpts.d.ts +9 -9
- package/types/Geometry.d.ts +65 -40
- package/types/Matrix4.d.ts +47 -47
- package/types/SVGConfig.d.ts +79 -76
- package/types/TreeConfig.d.ts +36 -24
- package/uni-app/ui-canvas.vue +9 -31
- package/.editorconfig +0 -19
- package/.eslintrc.js +0 -26
package/src/common/svg/config.ts
CHANGED
|
@@ -30,20 +30,24 @@ export const initText = (
|
|
|
30
30
|
setAttribute(
|
|
31
31
|
el,
|
|
32
32
|
"dy",
|
|
33
|
-
{
|
|
34
|
-
top: config["fontSize"] * 0.5,
|
|
33
|
+
({
|
|
34
|
+
top: (config["fontSize"] as number) * 0.5,
|
|
35
35
|
middle: 0,
|
|
36
|
-
bottom: -config["fontSize"] * 0.5,
|
|
37
|
-
}
|
|
36
|
+
bottom: -(config["fontSize"] as number) * 0.5,
|
|
37
|
+
} as {
|
|
38
|
+
[key: string]: number
|
|
39
|
+
})[config.textBaseline as string]
|
|
38
40
|
)
|
|
39
41
|
|
|
40
42
|
setStyle(el, {
|
|
41
43
|
// 文字对齐方式
|
|
42
|
-
"text-anchor": {
|
|
44
|
+
"text-anchor": ({
|
|
43
45
|
left: "start",
|
|
44
46
|
right: "end",
|
|
45
47
|
center: "middle",
|
|
46
|
-
}
|
|
48
|
+
} as {
|
|
49
|
+
[key: string]: string
|
|
50
|
+
})[config.textAlign as string],
|
|
47
51
|
"dominant-baseline": "central",
|
|
48
52
|
|
|
49
53
|
// 文字大小和字体设置
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import { initDefs } from './config'
|
|
2
|
-
import { toNode, setAttribute } from "./tool"
|
|
3
|
-
|
|
4
|
-
// 线性渐变
|
|
5
|
-
export const linearGradient = function (el: SVGElement, x0: number, y0: number, x1: number, y1: number) {
|
|
6
|
-
|
|
7
|
-
const defs = initDefs(el)
|
|
8
|
-
const gradientId = "vislite-lg-" + new Date().valueOf() + "-" + Math.random()
|
|
9
|
-
|
|
10
|
-
const linearGradient = toNode("linearGradient")
|
|
11
|
-
defs.appendChild(linearGradient)
|
|
12
|
-
setAttribute(linearGradient, "id", gradientId)
|
|
13
|
-
setAttribute(linearGradient, "x1", x0 + "%")
|
|
14
|
-
setAttribute(linearGradient, "y1", y0 + "%")
|
|
15
|
-
setAttribute(linearGradient, "x2", x1 + "%")
|
|
16
|
-
setAttribute(linearGradient, "y2", y1 + "%")
|
|
17
|
-
|
|
18
|
-
const enhanceGradient = {
|
|
19
|
-
"value": function () {
|
|
20
|
-
return "url(#" + gradientId + ")";
|
|
21
|
-
},
|
|
22
|
-
"setColor": function (stop: number, color: string) {
|
|
23
|
-
|
|
24
|
-
const stopEl = toNode("stop")
|
|
25
|
-
linearGradient.appendChild(stopEl)
|
|
26
|
-
setAttribute(stopEl, "offset", (stop * 100) + "%")
|
|
27
|
-
setAttribute(stopEl, "style", "stop-color:" + color + ";")
|
|
28
|
-
|
|
29
|
-
return enhanceGradient
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return enhanceGradient
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// 环形渐变
|
|
36
|
-
export const radialGradient = function (el: SVGElement, cx: number, cy: number, r: number) {
|
|
37
|
-
|
|
38
|
-
const defs = initDefs(el)
|
|
39
|
-
const gradientId = "vislite-rg-" + new Date().valueOf() + "-" + Math.random()
|
|
40
|
-
|
|
41
|
-
const radialGradient = toNode("radialGradient")
|
|
42
|
-
defs.appendChild(radialGradient)
|
|
43
|
-
setAttribute(radialGradient, "id", gradientId)
|
|
44
|
-
setAttribute(radialGradient, "cx", cx + "%")
|
|
45
|
-
setAttribute(radialGradient, "cy", cy + "%")
|
|
46
|
-
setAttribute(radialGradient, "r", r + "%")
|
|
47
|
-
|
|
48
|
-
const enhanceGradient = {
|
|
49
|
-
"value": function () {
|
|
50
|
-
return "url(#" + gradientId + ")";
|
|
51
|
-
},
|
|
52
|
-
"setColor": function (stop: number, color: string) {
|
|
53
|
-
|
|
54
|
-
const stopEl = toNode("stop")
|
|
55
|
-
radialGradient.appendChild(stopEl)
|
|
56
|
-
setAttribute(stopEl, "offset", (stop * 100) + "%")
|
|
57
|
-
setAttribute(stopEl, "style", "stop-color:" + color + ";")
|
|
58
|
-
|
|
59
|
-
return enhanceGradient
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return enhanceGradient
|
|
63
|
-
}
|
|
1
|
+
import { initDefs } from './config'
|
|
2
|
+
import { toNode, setAttribute } from "./tool"
|
|
3
|
+
|
|
4
|
+
// 线性渐变
|
|
5
|
+
export const linearGradient = function (el: SVGElement, x0: number, y0: number, x1: number, y1: number) {
|
|
6
|
+
|
|
7
|
+
const defs = initDefs(el)
|
|
8
|
+
const gradientId = "vislite-lg-" + new Date().valueOf() + "-" + Math.random()
|
|
9
|
+
|
|
10
|
+
const linearGradient = toNode("linearGradient")
|
|
11
|
+
defs.appendChild(linearGradient)
|
|
12
|
+
setAttribute(linearGradient, "id", gradientId)
|
|
13
|
+
setAttribute(linearGradient, "x1", x0 + "%")
|
|
14
|
+
setAttribute(linearGradient, "y1", y0 + "%")
|
|
15
|
+
setAttribute(linearGradient, "x2", x1 + "%")
|
|
16
|
+
setAttribute(linearGradient, "y2", y1 + "%")
|
|
17
|
+
|
|
18
|
+
const enhanceGradient = {
|
|
19
|
+
"value": function () {
|
|
20
|
+
return "url(#" + gradientId + ")";
|
|
21
|
+
},
|
|
22
|
+
"setColor": function (stop: number, color: string) {
|
|
23
|
+
|
|
24
|
+
const stopEl = toNode("stop")
|
|
25
|
+
linearGradient.appendChild(stopEl)
|
|
26
|
+
setAttribute(stopEl, "offset", (stop * 100) + "%")
|
|
27
|
+
setAttribute(stopEl, "style", "stop-color:" + color + ";")
|
|
28
|
+
|
|
29
|
+
return enhanceGradient
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return enhanceGradient
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 环形渐变
|
|
36
|
+
export const radialGradient = function (el: SVGElement, cx: number, cy: number, r: number) {
|
|
37
|
+
|
|
38
|
+
const defs = initDefs(el)
|
|
39
|
+
const gradientId = "vislite-rg-" + new Date().valueOf() + "-" + Math.random()
|
|
40
|
+
|
|
41
|
+
const radialGradient = toNode("radialGradient")
|
|
42
|
+
defs.appendChild(radialGradient)
|
|
43
|
+
setAttribute(radialGradient, "id", gradientId)
|
|
44
|
+
setAttribute(radialGradient, "cx", cx + "%")
|
|
45
|
+
setAttribute(radialGradient, "cy", cy + "%")
|
|
46
|
+
setAttribute(radialGradient, "r", r + "%")
|
|
47
|
+
|
|
48
|
+
const enhanceGradient = {
|
|
49
|
+
"value": function () {
|
|
50
|
+
return "url(#" + gradientId + ")";
|
|
51
|
+
},
|
|
52
|
+
"setColor": function (stop: number, color: string) {
|
|
53
|
+
|
|
54
|
+
const stopEl = toNode("stop")
|
|
55
|
+
radialGradient.appendChild(stopEl)
|
|
56
|
+
setAttribute(stopEl, "offset", (stop * 100) + "%")
|
|
57
|
+
setAttribute(stopEl, "style", "stop-color:" + color + ";")
|
|
58
|
+
|
|
59
|
+
return enhanceGradient
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return enhanceGradient
|
|
63
|
+
}
|
package/src/common/svg/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type SVGConfigType from "../../../types/SVGConfig"
|
|
1
|
+
import type { default as SVGConfigType, svgElType, svgBoardType } from "../../../types/SVGConfig"
|
|
2
2
|
import type { arcCapType, textAlignType, textBaselineType } from "../../../types/painterConfig"
|
|
3
3
|
|
|
4
4
|
import { initText, initCircle, initPath, initRect, initArc } from "./config"
|
|
@@ -86,7 +86,7 @@ class SVG {
|
|
|
86
86
|
// el可以是结点或字符串,字符串的话表示节点名称
|
|
87
87
|
// context可选,表示追加位置,可选,默认根svg
|
|
88
88
|
// 此外,和appendBoard等操作一样,执行后新加入的结点会自动变成应用节点
|
|
89
|
-
appendEl(el:
|
|
89
|
+
appendEl(el: svgElType, context?: SVGElement) {
|
|
90
90
|
context = context || this.__svg
|
|
91
91
|
|
|
92
92
|
if (typeof el == "string") el = toNode(el)
|
|
@@ -99,8 +99,8 @@ class SVG {
|
|
|
99
99
|
// 追加绘制板
|
|
100
100
|
// 参数和appendEl类似,只是el如果是字符串的话,表示需要绘制对应什么内容,
|
|
101
101
|
// 比如el = “arc”,表示画弧(不是路径arc),那么我们会创建path节点,因为我们是使用path实现的
|
|
102
|
-
appendBoard(el:
|
|
103
|
-
let _el = el
|
|
102
|
+
appendBoard(el: svgBoardType, context?: SVGElement) {
|
|
103
|
+
let _el: svgBoardType | string = el
|
|
104
104
|
|
|
105
105
|
if (typeof el == "string")
|
|
106
106
|
_el =
|
|
@@ -113,7 +113,7 @@ class SVG {
|
|
|
113
113
|
}[el] || ""
|
|
114
114
|
|
|
115
115
|
if (_el == "") throw new Error("Unsupported drawing method:" + el)
|
|
116
|
-
return this.appendEl(_el, context)
|
|
116
|
+
return this.appendEl(_el as svgElType, context)
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
// 删除当前维护的节点
|
package/src/common/svg/tool.ts
CHANGED
|
@@ -29,17 +29,17 @@ export function getAttribute(el: SVGElement, key: string) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export function full(el: SVGElement, config: SVGConfigType) {
|
|
32
|
-
_setAttribute(el, "stroke", config.strokeStyle)
|
|
33
|
-
_setAttribute(el, "fill", config.fillStyle)
|
|
34
|
-
_setAttribute(el, "stroke-dasharray", config.lineDash.join(','))
|
|
32
|
+
_setAttribute(el, "stroke", config.strokeStyle as string)
|
|
33
|
+
_setAttribute(el, "fill", config.fillStyle as string)
|
|
34
|
+
_setAttribute(el, "stroke-dasharray", (config.lineDash as Array<number>).join(','))
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export function fill(el: SVGElement, config: SVGConfigType) {
|
|
38
|
-
_setAttribute(el, "fill", config.fillStyle)
|
|
38
|
+
_setAttribute(el, "fill", config.fillStyle as string)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export function stroke(el: SVGElement, config: SVGConfigType) {
|
|
42
|
-
_setAttribute(el, "stroke", config.strokeStyle)
|
|
42
|
+
_setAttribute(el, "stroke", config.strokeStyle as string)
|
|
43
43
|
_setAttribute(el, "fill", "none")
|
|
44
|
-
_setAttribute(el, "stroke-dasharray", config.lineDash.join(','))
|
|
44
|
+
_setAttribute(el, "stroke-dasharray", (config.lineDash as Array<number>).join(','))
|
|
45
45
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type TreeConfigType from '../../../types/TreeConfig'
|
|
1
|
+
import type { default as TreeConfigType, rootType, childrenType, idType } from '../../../types/TreeConfig'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 根据配置的层次关系(配置的id,child,root)把原始数据变成内部结构,方便后期位置计算
|
|
@@ -13,12 +13,14 @@ import type TreeConfigType from '../../../types/TreeConfig'
|
|
|
13
13
|
* }
|
|
14
14
|
*/
|
|
15
15
|
export default (initTree: any, config: TreeConfigType) => {
|
|
16
|
-
const tempTree
|
|
16
|
+
const tempTree: {
|
|
17
|
+
[key: string]: any
|
|
18
|
+
} = {}
|
|
17
19
|
|
|
18
20
|
// 根结点
|
|
19
|
-
const temp = config.root(initTree)
|
|
21
|
+
const temp = (config.root as rootType)(initTree)
|
|
20
22
|
let id: number | string, rid: number | string
|
|
21
|
-
id = rid = config.id(temp)
|
|
23
|
+
id = rid = (config.id as idType)(temp)
|
|
22
24
|
tempTree[id] = {
|
|
23
25
|
"data": temp,
|
|
24
26
|
"pid": null,
|
|
@@ -32,10 +34,10 @@ export default (initTree: any, config: TreeConfigType) => {
|
|
|
32
34
|
|
|
33
35
|
// 根据传递的原始数据,生成内部统一结构
|
|
34
36
|
; (function createTree(pdata: any, pid: number | string) {
|
|
35
|
-
const children = config.children(pdata, initTree)
|
|
37
|
+
const children = (config.children as childrenType)(pdata, initTree)
|
|
36
38
|
num += children ? children.length : 0
|
|
37
39
|
for (let flag = 0; children && flag < children.length; flag++) {
|
|
38
|
-
id = config.id(children[flag])
|
|
40
|
+
id = (config.id as idType)(children[flag])
|
|
39
41
|
tempTree[pid].children.push(id);
|
|
40
42
|
tempTree[id] = {
|
|
41
43
|
"data": children[flag],
|
|
@@ -51,7 +51,7 @@ class BufferObject {
|
|
|
51
51
|
this.__painter = painter
|
|
52
52
|
this.__isElement = isElement
|
|
53
53
|
|
|
54
|
-
this.__buffer = newBuffer(painter)
|
|
54
|
+
this.__buffer = newBuffer(painter) as WebGLBuffer
|
|
55
55
|
this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -39,10 +39,10 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
39
39
|
|
|
40
40
|
// 写入颜色
|
|
41
41
|
painter.uniform4f(painter.getUniformLocation(shader.program, "u_color")
|
|
42
|
-
, mesh.material.color
|
|
43
|
-
, mesh.material.color
|
|
44
|
-
, mesh.material.color
|
|
45
|
-
, mesh.material.color
|
|
42
|
+
, mesh.material.color?.r as number
|
|
43
|
+
, mesh.material.color?.g as number
|
|
44
|
+
, mesh.material.color?.b as number
|
|
45
|
+
, mesh.material.color?.alpha as number)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// 多颜色
|
|
@@ -50,25 +50,25 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
50
50
|
|
|
51
51
|
// 写入颜色序列
|
|
52
52
|
new BufferObject(painter).use()
|
|
53
|
-
.write(mesh.material.colors
|
|
54
|
-
.divide(painter.getAttribLocation(shader.program, "a_color"), mesh.material.colors
|
|
53
|
+
.write(mesh.material.colors?.array as Float32Array)
|
|
54
|
+
.divide(painter.getAttribLocation(shader.program, "a_color"), mesh.material.colors?.itemSize as number, mesh.material.colors?.itemSize as number, 0)
|
|
55
55
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// 立方纹理
|
|
59
59
|
else if ("cube" in mesh.material) {
|
|
60
60
|
|
|
61
|
-
const size = (mesh.material.cube
|
|
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
|
|
|
65
65
|
getTexture(type, painter, 'cube').useCube([
|
|
66
|
-
mesh.material.cube
|
|
67
|
-
mesh.material.cube
|
|
68
|
-
mesh.material.cube
|
|
69
|
-
mesh.material.cube
|
|
70
|
-
mesh.material.cube
|
|
71
|
-
mesh.material.cube
|
|
66
|
+
mesh.material.cube?.right?.image.value,
|
|
67
|
+
mesh.material.cube?.left?.image.value,
|
|
68
|
+
mesh.material.cube?.top?.image.value,
|
|
69
|
+
mesh.material.cube?.bottom?.image.value,
|
|
70
|
+
mesh.material.cube?.far?.image.value,
|
|
71
|
+
mesh.material.cube?.near?.image.value
|
|
72
72
|
], size, size)
|
|
73
73
|
|
|
74
74
|
}
|
|
@@ -79,10 +79,10 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
79
79
|
painter.uniform1i(painter.getUniformLocation(shader.program, "u_sampler"), 0)
|
|
80
80
|
|
|
81
81
|
new BufferObject(painter).use()
|
|
82
|
-
.write(mesh.geometry.attributes.uv
|
|
83
|
-
.divide(painter.getAttribLocation(shader.program, "a_textcoord"), mesh.geometry.attributes.uv
|
|
82
|
+
.write(mesh.geometry.attributes.uv?.array as Float32Array)
|
|
83
|
+
.divide(painter.getAttribLocation(shader.program, "a_textcoord"), mesh.geometry.attributes.uv?.itemSize as number, 2, 0)
|
|
84
84
|
|
|
85
|
-
getTexture(type, painter, '2d').useImage(mesh.material.image
|
|
85
|
+
getTexture(type, painter, '2d').useImage(mesh.material.image?.value)
|
|
86
86
|
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
export default function (painter: WebGLRenderingContext) {
|
|
2
|
-
const width = painter.drawingBufferWidth, height = painter.drawingBufferHeight
|
|
3
|
-
|
|
4
|
-
const pixels = new Uint8Array(
|
|
5
|
-
4 * width * height
|
|
6
|
-
)
|
|
7
|
-
painter.readPixels(
|
|
8
|
-
0,
|
|
9
|
-
0,
|
|
10
|
-
width,
|
|
11
|
-
height,
|
|
12
|
-
painter.RGBA,
|
|
13
|
-
painter.UNSIGNED_BYTE,
|
|
14
|
-
pixels
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
return function (x: number, y: number): string {
|
|
18
|
-
y = height - y
|
|
19
|
-
|
|
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
|
-
|
|
25
|
-
return "rgba(" + pixelR + "," + pixelG + "," + pixelB + "," + pixelA + ")"
|
|
26
|
-
}
|
|
1
|
+
export default function (painter: WebGLRenderingContext) {
|
|
2
|
+
const width = painter.drawingBufferWidth, height = painter.drawingBufferHeight
|
|
3
|
+
|
|
4
|
+
const pixels = new Uint8Array(
|
|
5
|
+
4 * width * height
|
|
6
|
+
)
|
|
7
|
+
painter.readPixels(
|
|
8
|
+
0,
|
|
9
|
+
0,
|
|
10
|
+
width,
|
|
11
|
+
height,
|
|
12
|
+
painter.RGBA,
|
|
13
|
+
painter.UNSIGNED_BYTE,
|
|
14
|
+
pixels
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
return function (x: number, y: number): string {
|
|
18
|
+
y = height - y
|
|
19
|
+
|
|
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
|
+
|
|
25
|
+
return "rgba(" + pixelR + "," + pixelG + "," + pixelB + "," + pixelA + ")"
|
|
26
|
+
}
|
|
27
27
|
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import type { meshType } from '../../../types/Object3D'
|
|
2
|
-
|
|
3
|
-
import ShaderObject from './shader'
|
|
4
|
-
|
|
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'
|
|
14
|
-
|
|
15
|
-
const shaders = {}
|
|
16
|
-
export default function (type: string, painter: WebGLRenderingContext, mesh: meshType) {
|
|
17
|
-
|
|
18
|
-
const uniqueName = type +
|
|
19
|
-
(mesh.material.color ? "1" : "0") +
|
|
20
|
-
(mesh.material.colors ? "1" : "0") +
|
|
21
|
-
(mesh.material.image ? "1" : "0") +
|
|
22
|
-
(mesh.material.cube ? "1" : "0")
|
|
23
|
-
if (shaders[uniqueName]) return shaders[uniqueName].use()
|
|
24
|
-
|
|
25
|
-
// 顶点着色器
|
|
26
|
-
const vertexShader = {
|
|
27
|
-
[type + "1000"]: vsColor,
|
|
28
|
-
[type + "0100"]: vsColors,
|
|
29
|
-
[type + "0010"]: vsImage,
|
|
30
|
-
[type + "0001"]: vsCube
|
|
31
|
-
}[uniqueName].replace(/uniform +mat4 +u_matrix;/, `
|
|
32
|
-
uniform mat4 u_matrix_world;
|
|
33
|
-
uniform mat4 u_matrix_mesh;
|
|
34
|
-
uniform mat4 u_matrix_proporion;`).replace(/u_matrix +\* +a_position/, "u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position")
|
|
35
|
-
|
|
36
|
-
// 片段(元)着色器
|
|
37
|
-
const fragmentShader = {
|
|
38
|
-
[type + "1000"]: fsColor,
|
|
39
|
-
[type + "0100"]: fsColors,
|
|
40
|
-
[type + "0010"]: fsImage,
|
|
41
|
-
[type + "0001"]: fsCube
|
|
42
|
-
}[uniqueName]
|
|
43
|
-
|
|
44
|
-
// 启用着色器
|
|
45
|
-
const shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use()
|
|
46
|
-
|
|
47
|
-
shaders[uniqueName] = shader
|
|
48
|
-
return shader
|
|
1
|
+
import type { meshType } from '../../../types/Object3D'
|
|
2
|
+
|
|
3
|
+
import ShaderObject from './shader'
|
|
4
|
+
|
|
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'
|
|
14
|
+
|
|
15
|
+
const shaders = {}
|
|
16
|
+
export default function (type: string, painter: WebGLRenderingContext, mesh: meshType) {
|
|
17
|
+
|
|
18
|
+
const uniqueName = type +
|
|
19
|
+
(mesh.material.color ? "1" : "0") +
|
|
20
|
+
(mesh.material.colors ? "1" : "0") +
|
|
21
|
+
(mesh.material.image ? "1" : "0") +
|
|
22
|
+
(mesh.material.cube ? "1" : "0")
|
|
23
|
+
if (shaders[uniqueName]) return shaders[uniqueName].use()
|
|
24
|
+
|
|
25
|
+
// 顶点着色器
|
|
26
|
+
const vertexShader = {
|
|
27
|
+
[type + "1000"]: vsColor,
|
|
28
|
+
[type + "0100"]: vsColors,
|
|
29
|
+
[type + "0010"]: vsImage,
|
|
30
|
+
[type + "0001"]: vsCube
|
|
31
|
+
}[uniqueName].replace(/uniform +mat4 +u_matrix;/, `
|
|
32
|
+
uniform mat4 u_matrix_world;
|
|
33
|
+
uniform mat4 u_matrix_mesh;
|
|
34
|
+
uniform mat4 u_matrix_proporion;`).replace(/u_matrix +\* +a_position/, "u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position")
|
|
35
|
+
|
|
36
|
+
// 片段(元)着色器
|
|
37
|
+
const fragmentShader = {
|
|
38
|
+
[type + "1000"]: fsColor,
|
|
39
|
+
[type + "0100"]: fsColors,
|
|
40
|
+
[type + "0010"]: fsImage,
|
|
41
|
+
[type + "0001"]: fsCube
|
|
42
|
+
}[uniqueName]
|
|
43
|
+
|
|
44
|
+
// 启用着色器
|
|
45
|
+
const shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use()
|
|
46
|
+
|
|
47
|
+
shaders[uniqueName] = shader
|
|
48
|
+
return shader
|
|
49
49
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import TextureObject from './texture'
|
|
2
|
-
|
|
3
|
-
const textures = {}
|
|
4
|
-
export default function (type: string, painter: WebGLRenderingContext, kind: string) {
|
|
5
|
-
const uniqueName = type + "-" + kind
|
|
6
|
-
|
|
7
|
-
if (!textures[uniqueName]) {
|
|
8
|
-
textures[uniqueName] = new TextureObject(painter, kind)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return textures[uniqueName]
|
|
1
|
+
import TextureObject from './texture'
|
|
2
|
+
|
|
3
|
+
const textures = {}
|
|
4
|
+
export default function (type: string, painter: WebGLRenderingContext, kind: string) {
|
|
5
|
+
const uniqueName = type + "-" + kind
|
|
6
|
+
|
|
7
|
+
if (!textures[uniqueName]) {
|
|
8
|
+
textures[uniqueName] = new TextureObject(painter, kind)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return textures[uniqueName]
|
|
12
12
|
}
|
|
@@ -2,11 +2,11 @@ interface OptsType {
|
|
|
2
2
|
preserveDrawingBuffer?: boolean
|
|
3
3
|
}
|
|
4
4
|
export default function (canvas: HTMLCanvasElement, scale: number, opts: OptsType = {}) {
|
|
5
|
-
const names = ["
|
|
6
|
-
let painter =
|
|
5
|
+
const names = ["experimental-webgl", "webkit-3d", "moz-webgl"]
|
|
6
|
+
let painter = canvas.getContext("webgl", opts) as WebGL2RenderingContext
|
|
7
7
|
for (let i = 0; i < names.length; i++) {
|
|
8
8
|
try {
|
|
9
|
-
painter = canvas.getContext(names[i], opts)
|
|
9
|
+
painter = canvas.getContext(names[i], opts) as WebGL2RenderingContext
|
|
10
10
|
} catch (e) { }
|
|
11
11
|
if (painter) break
|
|
12
12
|
}
|
|
@@ -21,7 +21,9 @@ class WebGL {
|
|
|
21
21
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
22
22
|
private __getColor = (x: number, y: number) => "rgba(0,0,0,1)"
|
|
23
23
|
|
|
24
|
-
private __regionList
|
|
24
|
+
private __regionList: {
|
|
25
|
+
[key: string | number]: Array<number>
|
|
26
|
+
} = {} //区域映射表
|
|
25
27
|
private __regionAssemble = assemble(0, 1, 0.2, 3)
|
|
26
28
|
|
|
27
29
|
private __regionName = "" // 当前绘制的内容名称
|
|
@@ -43,7 +45,7 @@ class WebGL {
|
|
|
43
45
|
|
|
44
46
|
private __unique: number
|
|
45
47
|
|
|
46
|
-
constructor(ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement) {
|
|
48
|
+
constructor(ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement | null) {
|
|
47
49
|
this.__unique = new Date().valueOf()
|
|
48
50
|
|
|
49
51
|
this.painter = getWebGLContext(ViewCanvas, scale)
|
|
@@ -111,7 +113,7 @@ class WebGL {
|
|
|
111
113
|
if (!isUpdateRegion) needUpdate = true
|
|
112
114
|
|
|
113
115
|
const meshWorld = {
|
|
114
|
-
matrix: object3D.matrix
|
|
116
|
+
matrix: object3D.matrix?.value() as Array<number>
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
const globalWorld = {
|
|
@@ -184,7 +186,7 @@ class WebGL {
|
|
|
184
186
|
}
|
|
185
187
|
|
|
186
188
|
// 设置当前绘制区域名称
|
|
187
|
-
setRegion(regionName: string | number) {
|
|
189
|
+
setRegion(regionName: string | number | undefined) {
|
|
188
190
|
this.__regionName = regionName + ""
|
|
189
191
|
|
|
190
192
|
if (regionName) {
|
|
@@ -32,7 +32,7 @@ const useShader = (painter: WebGLRenderingContext, vshaderSource: string, fshade
|
|
|
32
32
|
const fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource)
|
|
33
33
|
|
|
34
34
|
// 创建一个着色器程序
|
|
35
|
-
const glProgram = painter.createProgram()
|
|
35
|
+
const glProgram = painter.createProgram() as WebGLProgram
|
|
36
36
|
|
|
37
37
|
// 把前面创建的两个着色器对象添加到着色器程序中
|
|
38
38
|
painter.attachShader(glProgram, vertexShader)
|
|
@@ -52,7 +52,7 @@ class ShaderObject {
|
|
|
52
52
|
|
|
53
53
|
private __painter: WebGLRenderingContext
|
|
54
54
|
|
|
55
|
-
program: WebGLProgram
|
|
55
|
+
program: WebGLProgram | null = null
|
|
56
56
|
|
|
57
57
|
constructor(painter: WebGLRenderingContext) {
|
|
58
58
|
this.__painter = painter
|
|
@@ -67,7 +67,7 @@ class ShaderObject {
|
|
|
67
67
|
|
|
68
68
|
// 编译着色器程序
|
|
69
69
|
compile(vshaderSource: string, fshaderSource: string) {
|
|
70
|
-
this.program = useShader(this.__painter, vshaderSource, fshaderSource)
|
|
70
|
+
this.program = useShader(this.__painter, vshaderSource, fshaderSource) as WebGLProgram
|
|
71
71
|
return this
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -69,10 +69,10 @@ class TextureObject {
|
|
|
69
69
|
this.__type = {
|
|
70
70
|
"2d": painter.TEXTURE_2D,
|
|
71
71
|
"cube": painter.TEXTURE_CUBE_MAP
|
|
72
|
-
}[type]
|
|
72
|
+
}[type] as number
|
|
73
73
|
|
|
74
74
|
// 创建纹理
|
|
75
|
-
this.__texture = initTexture(painter, this.__type, unit)
|
|
75
|
+
this.__texture = initTexture(painter, this.__type, unit) as WebGLTexture
|
|
76
76
|
|
|
77
77
|
// 配置纹理
|
|
78
78
|
painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST)
|