vislite 0.6.0-alpha.2 → 0.6.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/.eslintrc.js +3 -1
- package/CHANGELOG +1 -1
- package/README.md +11 -3
- package/lib/Buffer/index.umd.js +2 -2
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +2 -2
- package/lib/Canvas/index.umd.min.js +2 -2
- 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 +2 -2
- 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 +2 -2
- package/lib/OralCanvas/index.es.min.js +2 -2
- package/lib/OralWebGL/index.es.js +2 -2
- package/lib/OralWebGL/index.es.min.js +2 -2
- package/lib/SVG/index.umd.js +2 -2
- 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 +2 -2
- package/lib/Texture/index.umd.min.js +2 -2
- package/lib/TreeLayout/index.umd.js +2 -2
- package/lib/TreeLayout/index.umd.min.js +2 -2
- package/lib/WebGL/index.umd.js +2 -2
- package/lib/WebGL/index.umd.min.js +2 -2
- 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 +2 -2
- package/lib/getWebGLContext/index.umd.min.js +2 -2
- package/lib/index.umd.js +2 -2
- package/lib/index.umd.min.js +2 -2
- 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 +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 +2 -2
- package/lib/viewHandler/index.umd.min.js +2 -2
- package/package.json +1 -1
- package/src/Canvas.ts +70 -70
- package/src/Eoap.ts +66 -66
- package/src/Geometry.ts +82 -82
- package/src/Matrix4/move.ts +12 -12
- package/src/Matrix4/rotate.ts +15 -15
- package/src/Matrix4/transform.ts +64 -64
- package/src/Mercator.ts +27 -27
- package/src/SVG.ts +24 -24
- package/src/WebGL.ts +66 -66
- package/src/animation.ts +98 -98
- package/src/common/assemble.ts +22 -22
- 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/painter.ts +417 -417
- package/src/common/geometry/prism-horizontal.ts +35 -35
- package/src/common/geometry/prism-vertical.ts +40 -40
- package/src/common/geometry/sphere-fragment.ts +40 -40
- package/src/common/geometry/tool/circle.ts +11 -11
- package/src/common/mergeOption.ts +6 -6
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +186 -186
- package/src/common/svg/gradient.ts +63 -63
- package/src/common/svg/index.ts +356 -356
- package/src/common/svg/tool.ts +44 -44
- package/src/common/tree/toInnerTree.ts +57 -57
- package/src/common/tree/toPlainTree.ts +132 -132
- package/src/common/webgl/buffer.ts +79 -79
- package/src/common/webgl/doDraw.ts +108 -108
- 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 +28 -28
- package/src/common/webgl/index.ts +224 -224
- package/src/common/webgl/shader.ts +75 -75
- package/src/common/webgl/texture.ts +97 -97
- 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/move.ts +7 -7
- package/src/resizeObserver.ts +37 -37
- package/src/rotate.ts +7 -7
- package/src/throttle.ts +52 -52
- package/src/viewHandler.ts +158 -158
- package/types/CanvasOption.d.ts +8 -8
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
import BufferObject from './buffer'
|
|
2
|
-
|
|
3
|
-
import getTexture from './getTexture'
|
|
4
|
-
import getShader from './getShader'
|
|
5
|
-
|
|
6
|
-
interface MeshWorldType {
|
|
7
|
-
matrix: number[]
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface GlobalWorldType {
|
|
11
|
-
matrix: number[]
|
|
12
|
-
proporion: number[]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
import { meshType } from '../../../types/Object3D'
|
|
16
|
-
|
|
17
|
-
export default function (type: string, painter: WebGLRenderingContext, mesh: meshType, meshWorld: MeshWorldType, globalWorld: GlobalWorldType) {
|
|
18
|
-
const shader = getShader(type, painter, mesh)
|
|
19
|
-
|
|
20
|
-
// 点数据写入缓冲区
|
|
21
|
-
new BufferObject(painter).use()
|
|
22
|
-
.write(mesh.geometry.attributes.position.array as Float32Array)
|
|
23
|
-
.divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, mesh.geometry.attributes.position.itemSize, 0)
|
|
24
|
-
|
|
25
|
-
// 写入矩阵
|
|
26
|
-
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix)
|
|
27
|
-
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_proporion"), false, globalWorld.proporion)
|
|
28
|
-
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_mesh"), false, meshWorld.matrix)
|
|
29
|
-
|
|
30
|
-
// 如果有法向量数据
|
|
31
|
-
if (mesh.geometry.attributes.normal) {
|
|
32
|
-
new BufferObject(painter).use()
|
|
33
|
-
.write(mesh.geometry.attributes.normal.array as Float32Array)
|
|
34
|
-
.divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, mesh.geometry.attributes.normal.itemSize, 0)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 颜色
|
|
38
|
-
if ("color" in mesh.material) {
|
|
39
|
-
|
|
40
|
-
// 写入颜色
|
|
41
|
-
painter.uniform4f(painter.getUniformLocation(shader.program, "u_color")
|
|
42
|
-
, mesh.material.color.r
|
|
43
|
-
, mesh.material.color.g
|
|
44
|
-
, mesh.material.color.b
|
|
45
|
-
, mesh.material.color.alpha)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// 多颜色
|
|
49
|
-
if ("colors" in mesh.material) {
|
|
50
|
-
|
|
51
|
-
// 写入颜色序列
|
|
52
|
-
new BufferObject(painter).use()
|
|
53
|
-
.write(mesh.material.colors.array as Float32Array)
|
|
54
|
-
.divide(painter.getAttribLocation(shader.program, "a_color"), mesh.material.colors.itemSize, mesh.material.colors.itemSize, 0)
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// 立方纹理
|
|
59
|
-
else if ("cube" in mesh.material) {
|
|
60
|
-
|
|
61
|
-
const size = (mesh.material.cube.right.image.value as any).width
|
|
62
|
-
|
|
63
|
-
painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0)
|
|
64
|
-
|
|
65
|
-
getTexture(type, painter, 'cube').useCube([
|
|
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
|
-
], size, size)
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// 二维纹理
|
|
77
|
-
else if ("image" in mesh.material) {
|
|
78
|
-
|
|
79
|
-
painter.uniform1i(painter.getUniformLocation(shader.program, "u_sampler"), 0)
|
|
80
|
-
|
|
81
|
-
new BufferObject(painter).use()
|
|
82
|
-
.write(mesh.geometry.attributes.uv.array as Float32Array)
|
|
83
|
-
.divide(painter.getAttribLocation(shader.program, "a_textcoord"), mesh.geometry.attributes.uv.itemSize, 2, 0)
|
|
84
|
-
|
|
85
|
-
getTexture(type, painter, '2d').useImage(mesh.material.image.value)
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// 如果使用了索引
|
|
90
|
-
if (mesh.geometry.index) {
|
|
91
|
-
|
|
92
|
-
// 索引数据
|
|
93
|
-
new BufferObject(painter, true).use()
|
|
94
|
-
.write(mesh.geometry.index.array as Uint8Array)
|
|
95
|
-
|
|
96
|
-
// 绘制
|
|
97
|
-
painter.drawElements(painter[mesh.geometry.type], mesh.geometry.index.count, painter.UNSIGNED_BYTE, 0)
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// 否则
|
|
102
|
-
else {
|
|
103
|
-
|
|
104
|
-
// 绘制
|
|
105
|
-
painter.drawArrays(painter[mesh.geometry.type], 0, mesh.geometry.attributes.position.count)
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
1
|
+
import BufferObject from './buffer'
|
|
2
|
+
|
|
3
|
+
import getTexture from './getTexture'
|
|
4
|
+
import getShader from './getShader'
|
|
5
|
+
|
|
6
|
+
interface MeshWorldType {
|
|
7
|
+
matrix: number[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface GlobalWorldType {
|
|
11
|
+
matrix: number[]
|
|
12
|
+
proporion: number[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
import { meshType } from '../../../types/Object3D'
|
|
16
|
+
|
|
17
|
+
export default function (type: string, painter: WebGLRenderingContext, mesh: meshType, meshWorld: MeshWorldType, globalWorld: GlobalWorldType) {
|
|
18
|
+
const shader = getShader(type, painter, mesh)
|
|
19
|
+
|
|
20
|
+
// 点数据写入缓冲区
|
|
21
|
+
new BufferObject(painter).use()
|
|
22
|
+
.write(mesh.geometry.attributes.position.array as Float32Array)
|
|
23
|
+
.divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, mesh.geometry.attributes.position.itemSize, 0)
|
|
24
|
+
|
|
25
|
+
// 写入矩阵
|
|
26
|
+
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix)
|
|
27
|
+
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_proporion"), false, globalWorld.proporion)
|
|
28
|
+
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_mesh"), false, meshWorld.matrix)
|
|
29
|
+
|
|
30
|
+
// 如果有法向量数据
|
|
31
|
+
if (mesh.geometry.attributes.normal) {
|
|
32
|
+
new BufferObject(painter).use()
|
|
33
|
+
.write(mesh.geometry.attributes.normal.array as Float32Array)
|
|
34
|
+
.divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, mesh.geometry.attributes.normal.itemSize, 0)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 颜色
|
|
38
|
+
if ("color" in mesh.material) {
|
|
39
|
+
|
|
40
|
+
// 写入颜色
|
|
41
|
+
painter.uniform4f(painter.getUniformLocation(shader.program, "u_color")
|
|
42
|
+
, mesh.material.color.r
|
|
43
|
+
, mesh.material.color.g
|
|
44
|
+
, mesh.material.color.b
|
|
45
|
+
, mesh.material.color.alpha)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 多颜色
|
|
49
|
+
if ("colors" in mesh.material) {
|
|
50
|
+
|
|
51
|
+
// 写入颜色序列
|
|
52
|
+
new BufferObject(painter).use()
|
|
53
|
+
.write(mesh.material.colors.array as Float32Array)
|
|
54
|
+
.divide(painter.getAttribLocation(shader.program, "a_color"), mesh.material.colors.itemSize, mesh.material.colors.itemSize, 0)
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 立方纹理
|
|
59
|
+
else if ("cube" in mesh.material) {
|
|
60
|
+
|
|
61
|
+
const size = (mesh.material.cube.right.image.value as any).width
|
|
62
|
+
|
|
63
|
+
painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0)
|
|
64
|
+
|
|
65
|
+
getTexture(type, painter, 'cube').useCube([
|
|
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
|
+
], size, size)
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 二维纹理
|
|
77
|
+
else if ("image" in mesh.material) {
|
|
78
|
+
|
|
79
|
+
painter.uniform1i(painter.getUniformLocation(shader.program, "u_sampler"), 0)
|
|
80
|
+
|
|
81
|
+
new BufferObject(painter).use()
|
|
82
|
+
.write(mesh.geometry.attributes.uv.array as Float32Array)
|
|
83
|
+
.divide(painter.getAttribLocation(shader.program, "a_textcoord"), mesh.geometry.attributes.uv.itemSize, 2, 0)
|
|
84
|
+
|
|
85
|
+
getTexture(type, painter, '2d').useImage(mesh.material.image.value)
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 如果使用了索引
|
|
90
|
+
if (mesh.geometry.index) {
|
|
91
|
+
|
|
92
|
+
// 索引数据
|
|
93
|
+
new BufferObject(painter, true).use()
|
|
94
|
+
.write(mesh.geometry.index.array as Uint8Array)
|
|
95
|
+
|
|
96
|
+
// 绘制
|
|
97
|
+
painter.drawElements(painter[mesh.geometry.type], mesh.geometry.index.count, painter.UNSIGNED_BYTE, 0)
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 否则
|
|
102
|
+
else {
|
|
103
|
+
|
|
104
|
+
// 绘制
|
|
105
|
+
painter.drawArrays(painter[mesh.geometry.type], 0, mesh.geometry.attributes.position.count)
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
109
|
}
|
|
@@ -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
|
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
interface OptsType {
|
|
2
|
-
preserveDrawingBuffer?: boolean
|
|
3
|
-
}
|
|
4
|
-
export default function (canvas: HTMLCanvasElement, scale: number, opts: OptsType = {}) {
|
|
5
|
-
const names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"]
|
|
6
|
-
let painter = null
|
|
7
|
-
for (let i = 0; i < names.length; i++) {
|
|
8
|
-
try {
|
|
9
|
-
painter = canvas.getContext(names[i], opts)
|
|
10
|
-
} catch (e) { }
|
|
11
|
-
if (painter) break
|
|
12
|
-
}
|
|
13
|
-
if (!painter) throw new Error('Non canvas or browser does not support webgl.')
|
|
14
|
-
|
|
15
|
-
const width = painter.canvas.width, height = painter.canvas.height
|
|
16
|
-
|
|
17
|
-
const viewWidth = width * scale
|
|
18
|
-
const viewHeight = height * scale
|
|
19
|
-
|
|
20
|
-
painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight)
|
|
21
|
-
|
|
22
|
-
// https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/depthFunc
|
|
23
|
-
painter.depthFunc(painter.LEQUAL)
|
|
24
|
-
|
|
25
|
-
// 开启深度计算
|
|
26
|
-
painter.enable(painter.DEPTH_TEST);
|
|
27
|
-
|
|
28
|
-
return painter
|
|
1
|
+
interface OptsType {
|
|
2
|
+
preserveDrawingBuffer?: boolean
|
|
3
|
+
}
|
|
4
|
+
export default function (canvas: HTMLCanvasElement, scale: number, opts: OptsType = {}) {
|
|
5
|
+
const names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"]
|
|
6
|
+
let painter = null
|
|
7
|
+
for (let i = 0; i < names.length; i++) {
|
|
8
|
+
try {
|
|
9
|
+
painter = canvas.getContext(names[i], opts)
|
|
10
|
+
} catch (e) { }
|
|
11
|
+
if (painter) break
|
|
12
|
+
}
|
|
13
|
+
if (!painter) throw new Error('Non canvas or browser does not support webgl.')
|
|
14
|
+
|
|
15
|
+
const width = painter.canvas.width, height = painter.canvas.height
|
|
16
|
+
|
|
17
|
+
const viewWidth = width * scale
|
|
18
|
+
const viewHeight = height * scale
|
|
19
|
+
|
|
20
|
+
painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight)
|
|
21
|
+
|
|
22
|
+
// https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/depthFunc
|
|
23
|
+
painter.depthFunc(painter.LEQUAL)
|
|
24
|
+
|
|
25
|
+
// 开启深度计算
|
|
26
|
+
painter.enable(painter.DEPTH_TEST);
|
|
27
|
+
|
|
28
|
+
return painter
|
|
29
29
|
}
|