vislite 0.8.0 → 0.8.1-alpha.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 +212 -209
- package/README.md +136 -144
- package/lib/Buffer/index.umd.js +36 -36
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +691 -691
- package/lib/Canvas/index.umd.min.js +2 -2
- package/lib/Cardinal/index.umd.js +91 -91
- package/lib/Cardinal/index.umd.min.js +2 -2
- package/lib/Eoap/index.umd.js +34 -34
- package/lib/Eoap/index.umd.min.js +2 -2
- package/lib/Geometry/index.umd.js +286 -286
- package/lib/Geometry/index.umd.min.js +2 -2
- package/lib/Hermite/index.umd.js +36 -36
- package/lib/Hermite/index.umd.min.js +2 -2
- package/lib/Matrix4/index.umd.js +125 -125
- package/lib/Matrix4/index.umd.min.js +2 -2
- package/lib/Mercator/index.umd.js +20 -20
- package/lib/Mercator/index.umd.min.js +2 -2
- package/lib/OralCanvas/index.es.js +634 -634
- package/lib/OralCanvas/index.es.min.js +2 -2
- package/lib/OralWebGL/index.es.js +552 -552
- package/lib/OralWebGL/index.es.min.js +2 -2
- package/lib/SVG/index.umd.js +471 -471
- package/lib/SVG/index.umd.min.js +2 -2
- package/lib/Shader/index.umd.js +61 -61
- package/lib/Shader/index.umd.min.js +2 -2
- package/lib/Texture/index.umd.js +54 -54
- package/lib/Texture/index.umd.min.js +2 -2
- package/lib/TreeLayout/index.umd.js +368 -368
- package/lib/TreeLayout/index.umd.min.js +2 -2
- package/lib/WebGL/index.umd.js +599 -599
- package/lib/WebGL/index.umd.min.js +2 -2
- package/lib/animation/index.umd.js +73 -73
- package/lib/animation/index.umd.min.js +2 -2
- package/lib/formatColor/index.umd.js +40 -40
- package/lib/formatColor/index.umd.min.js +2 -2
- package/lib/getLoopColors/index.umd.js +36 -36
- package/lib/getLoopColors/index.umd.min.js +2 -2
- package/lib/getWebGLContext/index.umd.js +63 -63
- package/lib/getWebGLContext/index.umd.min.js +2 -2
- package/lib/index.umd.js +2955 -2955
- package/lib/index.umd.min.js +2 -2
- package/lib/move/index.umd.js +8 -8
- package/lib/move/index.umd.min.js +2 -2
- package/lib/resizeObserver/index.umd.js +30 -30
- package/lib/resizeObserver/index.umd.min.js +2 -2
- package/lib/rotate/index.umd.js +8 -8
- package/lib/rotate/index.umd.min.js +2 -2
- package/lib/ruler/index.umd.js +138 -138
- package/lib/ruler/index.umd.min.js +2 -2
- package/lib/scale/index.umd.js +7 -7
- package/lib/scale/index.umd.min.js +2 -2
- package/lib/throttle/index.umd.js +49 -49
- package/lib/throttle/index.umd.min.js +2 -2
- package/lib/viewHandler/index.umd.js +120 -120
- package/lib/viewHandler/index.umd.min.js +2 -2
- package/miniprogram/ui-canvas/drawImage.js +34 -0
- package/miniprogram/ui-canvas/index.js +10 -2
- package/package/getWebGLContext/index.ts +40 -40
- package/package.json +70 -70
- package/src/Canvas.ts +72 -72
- package/src/Geometry.ts +210 -210
- package/src/WebGL.ts +66 -66
- package/src/common/canvas/index.ts +183 -183
- package/src/common/canvas/painter.ts +446 -446
- package/src/common/geometry/prism-horizontal.ts +50 -50
- package/src/common/geometry/prism-vertical.ts +55 -55
- package/src/common/geometry/tool/circle.ts +17 -17
- package/src/common/geometry/tool/rotateLine.ts +48 -48
- package/src/common/geometry/tool/triangles.ts +23 -23
- package/src/common/webgl/getWebGLContext.ts +45 -45
- package/src/common/webgl/index.ts +227 -227
- package/types/Canvas.d.ts +318 -318
- package/types/Geometry.d.ts +132 -132
- package/types/WebGLOption.d.ts +14 -14
- package/types/getWebGLContext.d.ts +4 -4
- package/types/ui-canvas.d.ts +4 -4
- package/uni-app/drawImage.js +17 -17
- package/uni-app/ui-canvas.vue +290 -290
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import rotate from '../../rotate'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 棱柱水平部分
|
|
5
|
-
* @param normal 是否需要法向量
|
|
6
|
-
* @param x 中心
|
|
7
|
-
* @param y
|
|
8
|
-
* @param z
|
|
9
|
-
* @param radius 半径
|
|
10
|
-
* @param num 份数
|
|
11
|
-
* @param d 方向(用于 表示是底还是顶,方便计算法向量)
|
|
12
|
-
* @param beginDeg 开始弧度,默认0
|
|
13
|
-
* @param deg 跨越弧度,默认2pi
|
|
14
|
-
* @returns 点数组
|
|
15
|
-
*/
|
|
16
|
-
export default function (normal: boolean, x: number, y: number, z: number, radius: number, num: number, d: number, beginDeg: number = 0, deg: number = Math.PI * 2) {
|
|
17
|
-
|
|
18
|
-
let beginX: number, beginZ: number
|
|
19
|
-
if (num == 4) {
|
|
20
|
-
const temp = radius / 1.414
|
|
21
|
-
beginX = x + temp
|
|
22
|
-
beginZ = z + temp
|
|
23
|
-
|
|
24
|
-
} else {
|
|
25
|
-
beginX = x + radius
|
|
26
|
-
beginZ = z
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let point = [beginX, beginZ]
|
|
30
|
-
if (beginDeg != 0) {
|
|
31
|
-
point = rotate(x, z, beginDeg, beginX, beginZ)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const points = []
|
|
35
|
-
const perDeg = deg / num
|
|
36
|
-
for (let i = 0; i < num; i++) {
|
|
37
|
-
|
|
38
|
-
points.push(x, y, z)
|
|
39
|
-
if (normal) points.push(0, d, 0)
|
|
40
|
-
|
|
41
|
-
points.push(point[0], y, point[1])
|
|
42
|
-
if (normal) points.push(0, d, 0)
|
|
43
|
-
|
|
44
|
-
point = rotate(x, z, perDeg * (i + 1), beginX, beginZ)
|
|
45
|
-
points.push(point[0], y, point[1])
|
|
46
|
-
if (normal) points.push(0, d, 0)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return points
|
|
50
|
-
}
|
|
1
|
+
import rotate from '../../rotate'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 棱柱水平部分
|
|
5
|
+
* @param normal 是否需要法向量
|
|
6
|
+
* @param x 中心
|
|
7
|
+
* @param y
|
|
8
|
+
* @param z
|
|
9
|
+
* @param radius 半径
|
|
10
|
+
* @param num 份数
|
|
11
|
+
* @param d 方向(用于 表示是底还是顶,方便计算法向量)
|
|
12
|
+
* @param beginDeg 开始弧度,默认0
|
|
13
|
+
* @param deg 跨越弧度,默认2pi
|
|
14
|
+
* @returns 点数组
|
|
15
|
+
*/
|
|
16
|
+
export default function (normal: boolean, x: number, y: number, z: number, radius: number, num: number, d: number, beginDeg: number = 0, deg: number = Math.PI * 2) {
|
|
17
|
+
|
|
18
|
+
let beginX: number, beginZ: number
|
|
19
|
+
if (num == 4) {
|
|
20
|
+
const temp = radius / 1.414
|
|
21
|
+
beginX = x + temp
|
|
22
|
+
beginZ = z + temp
|
|
23
|
+
|
|
24
|
+
} else {
|
|
25
|
+
beginX = x + radius
|
|
26
|
+
beginZ = z
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let point = [beginX, beginZ]
|
|
30
|
+
if (beginDeg != 0) {
|
|
31
|
+
point = rotate(x, z, beginDeg, beginX, beginZ)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const points = []
|
|
35
|
+
const perDeg = deg / num
|
|
36
|
+
for (let i = 0; i < num; i++) {
|
|
37
|
+
|
|
38
|
+
points.push(x, y, z)
|
|
39
|
+
if (normal) points.push(0, d, 0)
|
|
40
|
+
|
|
41
|
+
points.push(point[0], y, point[1])
|
|
42
|
+
if (normal) points.push(0, d, 0)
|
|
43
|
+
|
|
44
|
+
point = rotate(x, z, perDeg * (i + 1), beginX, beginZ)
|
|
45
|
+
points.push(point[0], y, point[1])
|
|
46
|
+
if (normal) points.push(0, d, 0)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return points
|
|
50
|
+
}
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import rotate from '../../rotate'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 棱柱垂直部分
|
|
5
|
-
* @param normal 是否需要法向量
|
|
6
|
-
* @param x 中心
|
|
7
|
-
* @param y
|
|
8
|
-
* @param z
|
|
9
|
-
* @param radius 半径
|
|
10
|
-
* @param height 高
|
|
11
|
-
* @param num 份数
|
|
12
|
-
* @param beginDeg 开始弧度,默认0
|
|
13
|
-
* @param deg 跨越弧度,默认2pi
|
|
14
|
-
* @returns 点数组
|
|
15
|
-
*/
|
|
16
|
-
export default function (normal: boolean, x: number, y: number, z: number, radius: number, height: number, num: number, beginDeg: number = 0, deg: number = Math.PI * 2) {
|
|
17
|
-
const points = []
|
|
18
|
-
let beginPosition: [number, number]
|
|
19
|
-
|
|
20
|
-
if (num == 4) {
|
|
21
|
-
beginPosition = rotate(x, z, Math.PI * 0.25, x - radius, z)
|
|
22
|
-
} else {
|
|
23
|
-
beginPosition = [x + radius, z]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (beginDeg != 0) {
|
|
27
|
-
beginPosition = rotate(x, z, beginDeg, ...beginPosition)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const perDeg = deg / num, degHalf = deg / (num * 2)
|
|
31
|
-
|
|
32
|
-
let endPosition: [number, number], normalPosition: [number, number, number] | [] = []
|
|
33
|
-
for (let i = 0; i < num; i++) {
|
|
34
|
-
|
|
35
|
-
endPosition = rotate(x, z, perDeg, ...beginPosition)
|
|
36
|
-
|
|
37
|
-
if (normal) {
|
|
38
|
-
const halfPosition = rotate(x, z, degHalf, ...beginPosition)
|
|
39
|
-
normalPosition = [halfPosition[0], 0, halfPosition[1]]
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
|
|
43
|
-
points.push(beginPosition[0], y + height, beginPosition[1], ...normalPosition)
|
|
44
|
-
points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
|
|
45
|
-
|
|
46
|
-
points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
|
|
47
|
-
points.push(endPosition[0], y, endPosition[1], ...normalPosition)
|
|
48
|
-
points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
beginPosition = endPosition
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return points
|
|
55
|
-
}
|
|
1
|
+
import rotate from '../../rotate'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 棱柱垂直部分
|
|
5
|
+
* @param normal 是否需要法向量
|
|
6
|
+
* @param x 中心
|
|
7
|
+
* @param y
|
|
8
|
+
* @param z
|
|
9
|
+
* @param radius 半径
|
|
10
|
+
* @param height 高
|
|
11
|
+
* @param num 份数
|
|
12
|
+
* @param beginDeg 开始弧度,默认0
|
|
13
|
+
* @param deg 跨越弧度,默认2pi
|
|
14
|
+
* @returns 点数组
|
|
15
|
+
*/
|
|
16
|
+
export default function (normal: boolean, x: number, y: number, z: number, radius: number, height: number, num: number, beginDeg: number = 0, deg: number = Math.PI * 2) {
|
|
17
|
+
const points = []
|
|
18
|
+
let beginPosition: [number, number]
|
|
19
|
+
|
|
20
|
+
if (num == 4) {
|
|
21
|
+
beginPosition = rotate(x, z, Math.PI * 0.25, x - radius, z)
|
|
22
|
+
} else {
|
|
23
|
+
beginPosition = [x + radius, z]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (beginDeg != 0) {
|
|
27
|
+
beginPosition = rotate(x, z, beginDeg, ...beginPosition)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const perDeg = deg / num, degHalf = deg / (num * 2)
|
|
31
|
+
|
|
32
|
+
let endPosition: [number, number], normalPosition: [number, number, number] | [] = []
|
|
33
|
+
for (let i = 0; i < num; i++) {
|
|
34
|
+
|
|
35
|
+
endPosition = rotate(x, z, perDeg, ...beginPosition)
|
|
36
|
+
|
|
37
|
+
if (normal) {
|
|
38
|
+
const halfPosition = rotate(x, z, degHalf, ...beginPosition)
|
|
39
|
+
normalPosition = [halfPosition[0], 0, halfPosition[1]]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
|
|
43
|
+
points.push(beginPosition[0], y + height, beginPosition[1], ...normalPosition)
|
|
44
|
+
points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
|
|
45
|
+
|
|
46
|
+
points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
|
|
47
|
+
points.push(endPosition[0], y, endPosition[1], ...normalPosition)
|
|
48
|
+
points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
beginPosition = endPosition
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return points
|
|
55
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 计算切割份数
|
|
3
|
-
* @param precision 精度
|
|
4
|
-
* @param radius 半径
|
|
5
|
-
* @param deg 需要跨越的弧度,默认圆(2pi)
|
|
6
|
-
* @returns 切割份数
|
|
7
|
-
*/
|
|
8
|
-
export const splitNum = function (precision: number, radius: number, deg: number = Math.PI * 2) {
|
|
9
|
-
|
|
10
|
-
// 根据切割弧度得出切割块数目
|
|
11
|
-
const num = Math.ceil(deg /
|
|
12
|
-
|
|
13
|
-
// 为了满足最小精度而得出的切割弧度
|
|
14
|
-
Math.asin(precision / radius) * 2)
|
|
15
|
-
|
|
16
|
-
return (isNaN(num) || num < 12) ? 12 : num
|
|
17
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 计算切割份数
|
|
3
|
+
* @param precision 精度
|
|
4
|
+
* @param radius 半径
|
|
5
|
+
* @param deg 需要跨越的弧度,默认圆(2pi)
|
|
6
|
+
* @returns 切割份数
|
|
7
|
+
*/
|
|
8
|
+
export const splitNum = function (precision: number, radius: number, deg: number = Math.PI * 2) {
|
|
9
|
+
|
|
10
|
+
// 根据切割弧度得出切割块数目
|
|
11
|
+
const num = Math.ceil(deg /
|
|
12
|
+
|
|
13
|
+
// 为了满足最小精度而得出的切割弧度
|
|
14
|
+
Math.asin(precision / radius) * 2)
|
|
15
|
+
|
|
16
|
+
return (isNaN(num) || num < 12) ? 12 : num
|
|
17
|
+
|
|
18
18
|
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 物体方向转换
|
|
3
|
-
* 由(x,y,z)转换成(x2-x,y2-y,z2-z)
|
|
4
|
-
* @param x
|
|
5
|
-
* @param y
|
|
6
|
-
* @param z
|
|
7
|
-
* @param x2
|
|
8
|
-
* @param y2
|
|
9
|
-
* @param z2
|
|
10
|
-
* @returns 点转换函数
|
|
11
|
-
*/
|
|
12
|
-
export default function (x: number, y: number, z: number, x2: number, y2: number, z2: number) {
|
|
13
|
-
return (x0: number, y0: number, z0: number, isNormal: boolean) => {
|
|
14
|
-
if (x == x2 && z == z2) return [x0, y0, z0]
|
|
15
|
-
|
|
16
|
-
let sin: number, cos: number, temp: Array<number>
|
|
17
|
-
|
|
18
|
-
// 第一步:归零化
|
|
19
|
-
let _x0 = x0 - (isNormal ? 0 : x), _y0 = y0 - (isNormal ? 0 : y), _z0 = z0 - (isNormal ? 0 : z) // 法向量起点本来就是原点
|
|
20
|
-
const _x2 = x2 - x, _y2 = y2 - y, _z2 = z2 - z
|
|
21
|
-
|
|
22
|
-
// 第二步:围绕OZ轴旋转
|
|
23
|
-
|
|
24
|
-
const __d = Math.sqrt(_x2 * _x2 + _z2 * _z2)
|
|
25
|
-
cos = _x2 / __d
|
|
26
|
-
sin = _z2 / __d
|
|
27
|
-
|
|
28
|
-
const _x2N = _z2 * sin + _x2 * cos
|
|
29
|
-
|
|
30
|
-
const d = Math.sqrt(_y2 * _y2 + _x2N * _x2N)
|
|
31
|
-
cos = _y2 / d
|
|
32
|
-
sin = _x2N / d
|
|
33
|
-
|
|
34
|
-
temp = [_y0, _x0]
|
|
35
|
-
_y0 = temp[0] * cos - temp[1] * sin
|
|
36
|
-
_x0 = temp[0] * sin + temp[1] * cos
|
|
37
|
-
|
|
38
|
-
// 第三步:围绕0Y轴旋转
|
|
39
|
-
cos = _x2 / __d
|
|
40
|
-
sin = _z2 / __d
|
|
41
|
-
|
|
42
|
-
temp = [_x0, _z0]
|
|
43
|
-
_x0 = temp[0] * cos - temp[1] * sin
|
|
44
|
-
_z0 = temp[0] * sin + temp[1] * cos
|
|
45
|
-
|
|
46
|
-
// 第四步:去零化(直接返回)
|
|
47
|
-
return [_x0 + (isNormal ? 0 : x), _y0 + (isNormal ? 0 : y), _z0 + (isNormal ? 0 : z)]
|
|
48
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 物体方向转换
|
|
3
|
+
* 由(x,y,z)转换成(x2-x,y2-y,z2-z)
|
|
4
|
+
* @param x
|
|
5
|
+
* @param y
|
|
6
|
+
* @param z
|
|
7
|
+
* @param x2
|
|
8
|
+
* @param y2
|
|
9
|
+
* @param z2
|
|
10
|
+
* @returns 点转换函数
|
|
11
|
+
*/
|
|
12
|
+
export default function (x: number, y: number, z: number, x2: number, y2: number, z2: number) {
|
|
13
|
+
return (x0: number, y0: number, z0: number, isNormal: boolean) => {
|
|
14
|
+
if (x == x2 && z == z2) return [x0, y0, z0]
|
|
15
|
+
|
|
16
|
+
let sin: number, cos: number, temp: Array<number>
|
|
17
|
+
|
|
18
|
+
// 第一步:归零化
|
|
19
|
+
let _x0 = x0 - (isNormal ? 0 : x), _y0 = y0 - (isNormal ? 0 : y), _z0 = z0 - (isNormal ? 0 : z) // 法向量起点本来就是原点
|
|
20
|
+
const _x2 = x2 - x, _y2 = y2 - y, _z2 = z2 - z
|
|
21
|
+
|
|
22
|
+
// 第二步:围绕OZ轴旋转
|
|
23
|
+
|
|
24
|
+
const __d = Math.sqrt(_x2 * _x2 + _z2 * _z2)
|
|
25
|
+
cos = _x2 / __d
|
|
26
|
+
sin = _z2 / __d
|
|
27
|
+
|
|
28
|
+
const _x2N = _z2 * sin + _x2 * cos
|
|
29
|
+
|
|
30
|
+
const d = Math.sqrt(_y2 * _y2 + _x2N * _x2N)
|
|
31
|
+
cos = _y2 / d
|
|
32
|
+
sin = _x2N / d
|
|
33
|
+
|
|
34
|
+
temp = [_y0, _x0]
|
|
35
|
+
_y0 = temp[0] * cos - temp[1] * sin
|
|
36
|
+
_x0 = temp[0] * sin + temp[1] * cos
|
|
37
|
+
|
|
38
|
+
// 第三步:围绕0Y轴旋转
|
|
39
|
+
cos = _x2 / __d
|
|
40
|
+
sin = _z2 / __d
|
|
41
|
+
|
|
42
|
+
temp = [_x0, _z0]
|
|
43
|
+
_x0 = temp[0] * cos - temp[1] * sin
|
|
44
|
+
_z0 = temp[0] * sin + temp[1] * cos
|
|
45
|
+
|
|
46
|
+
// 第四步:去零化(直接返回)
|
|
47
|
+
return [_x0 + (isNormal ? 0 : x), _y0 + (isNormal ? 0 : y), _z0 + (isNormal ? 0 : z)]
|
|
48
|
+
}
|
|
49
49
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 方向:ab x ac
|
|
3
|
-
* @param normal 是否需要法向量
|
|
4
|
-
* @param points [a1, b1, c1, a2, b2, c2, ...]
|
|
5
|
-
* @returns 完整的点数据
|
|
6
|
-
*/
|
|
7
|
-
export default function (normal: boolean, points: Array<number>) {
|
|
8
|
-
if (normal) {
|
|
9
|
-
const _points = []
|
|
10
|
-
for (let i = 0; i < points.length; i += 9) {
|
|
11
|
-
const ab = [points[i + 3] - points[i], points[i + 4] - points[i + 1], points[i + 5] - points[i + 2]]
|
|
12
|
-
const ac = [points[i + 6] - points[i], points[i + 7] - points[i + 1], points[i + 8] - points[i + 2]]
|
|
13
|
-
const normalVector = [ab[1] * ac[2] - ac[1] * ab[2], ab[2] * ac[0] - ab[0] * ac[2], ab[0] * ac[1] - ab[1] * ac[2]]
|
|
14
|
-
_points.push(
|
|
15
|
-
points[i], points[i + 1], points[i + 2], ...normalVector,
|
|
16
|
-
points[i + 3], points[i + 4], points[i + 5], ...normalVector,
|
|
17
|
-
points[i + 6], points[i + 7], points[i + 8], ...normalVector,
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
return _points
|
|
21
|
-
} else {
|
|
22
|
-
return points
|
|
23
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 方向:ab x ac
|
|
3
|
+
* @param normal 是否需要法向量
|
|
4
|
+
* @param points [a1, b1, c1, a2, b2, c2, ...]
|
|
5
|
+
* @returns 完整的点数据
|
|
6
|
+
*/
|
|
7
|
+
export default function (normal: boolean, points: Array<number>) {
|
|
8
|
+
if (normal) {
|
|
9
|
+
const _points = []
|
|
10
|
+
for (let i = 0; i < points.length; i += 9) {
|
|
11
|
+
const ab = [points[i + 3] - points[i], points[i + 4] - points[i + 1], points[i + 5] - points[i + 2]]
|
|
12
|
+
const ac = [points[i + 6] - points[i], points[i + 7] - points[i + 1], points[i + 8] - points[i + 2]]
|
|
13
|
+
const normalVector = [ab[1] * ac[2] - ac[1] * ab[2], ab[2] * ac[0] - ab[0] * ac[2], ab[0] * ac[1] - ab[1] * ac[2]]
|
|
14
|
+
_points.push(
|
|
15
|
+
points[i], points[i + 1], points[i + 2], ...normalVector,
|
|
16
|
+
points[i + 3], points[i + 4], points[i + 5], ...normalVector,
|
|
17
|
+
points[i + 6], points[i + 7], points[i + 8], ...normalVector,
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
return _points
|
|
21
|
+
} else {
|
|
22
|
+
return points
|
|
23
|
+
}
|
|
24
24
|
}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import type { WebGLmodeType } from "../../../types/getWebGLContext"
|
|
2
|
-
|
|
3
|
-
interface OptsType {
|
|
4
|
-
preserveDrawingBuffer?: boolean
|
|
5
|
-
}
|
|
6
|
-
export default function (canvas: HTMLCanvasElement, scale: number, opts: OptsType = {}, mode: WebGLmodeType = "scaleToFill") {
|
|
7
|
-
const names = ["experimental-webgl", "webkit-3d", "moz-webgl"]
|
|
8
|
-
let painter = canvas.getContext("webgl", opts) as WebGL2RenderingContext
|
|
9
|
-
for (let i = 0; i < names.length; i++) {
|
|
10
|
-
try {
|
|
11
|
-
painter = canvas.getContext(names[i], opts) as WebGL2RenderingContext
|
|
12
|
-
} catch (e) { }
|
|
13
|
-
if (painter) break
|
|
14
|
-
}
|
|
15
|
-
if (!painter) throw new Error('Non canvas or browser does not support webgl.')
|
|
16
|
-
|
|
17
|
-
const width = painter.canvas.width, height = painter.canvas.height
|
|
18
|
-
|
|
19
|
-
let scaleX = scale, scaleY = scale
|
|
20
|
-
if (mode == "aspectFit") {
|
|
21
|
-
if (width > height) {
|
|
22
|
-
scaleX *= height / width
|
|
23
|
-
} else if (height > width) {
|
|
24
|
-
scaleY *= width / height
|
|
25
|
-
}
|
|
26
|
-
} else if (mode == "aspectFill") {
|
|
27
|
-
if (width > height) {
|
|
28
|
-
scaleY *= width / height
|
|
29
|
-
} else if (height > width) {
|
|
30
|
-
scaleX *= height / width
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const viewWidth = width * scaleX
|
|
35
|
-
const viewHeight = height * scaleY
|
|
36
|
-
|
|
37
|
-
painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight)
|
|
38
|
-
|
|
39
|
-
// https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/depthFunc
|
|
40
|
-
painter.depthFunc(painter.LEQUAL)
|
|
41
|
-
|
|
42
|
-
// 开启深度计算
|
|
43
|
-
painter.enable(painter.DEPTH_TEST);
|
|
44
|
-
|
|
45
|
-
return painter
|
|
1
|
+
import type { WebGLmodeType } from "../../../types/getWebGLContext"
|
|
2
|
+
|
|
3
|
+
interface OptsType {
|
|
4
|
+
preserveDrawingBuffer?: boolean
|
|
5
|
+
}
|
|
6
|
+
export default function (canvas: HTMLCanvasElement, scale: number, opts: OptsType = {}, mode: WebGLmodeType = "scaleToFill") {
|
|
7
|
+
const names = ["experimental-webgl", "webkit-3d", "moz-webgl"]
|
|
8
|
+
let painter = canvas.getContext("webgl", opts) as WebGL2RenderingContext
|
|
9
|
+
for (let i = 0; i < names.length; i++) {
|
|
10
|
+
try {
|
|
11
|
+
painter = canvas.getContext(names[i], opts) as WebGL2RenderingContext
|
|
12
|
+
} catch (e) { }
|
|
13
|
+
if (painter) break
|
|
14
|
+
}
|
|
15
|
+
if (!painter) throw new Error('Non canvas or browser does not support webgl.')
|
|
16
|
+
|
|
17
|
+
const width = painter.canvas.width, height = painter.canvas.height
|
|
18
|
+
|
|
19
|
+
let scaleX = scale, scaleY = scale
|
|
20
|
+
if (mode == "aspectFit") {
|
|
21
|
+
if (width > height) {
|
|
22
|
+
scaleX *= height / width
|
|
23
|
+
} else if (height > width) {
|
|
24
|
+
scaleY *= width / height
|
|
25
|
+
}
|
|
26
|
+
} else if (mode == "aspectFill") {
|
|
27
|
+
if (width > height) {
|
|
28
|
+
scaleY *= width / height
|
|
29
|
+
} else if (height > width) {
|
|
30
|
+
scaleX *= height / width
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const viewWidth = width * scaleX
|
|
35
|
+
const viewHeight = height * scaleY
|
|
36
|
+
|
|
37
|
+
painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight)
|
|
38
|
+
|
|
39
|
+
// https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/depthFunc
|
|
40
|
+
painter.depthFunc(painter.LEQUAL)
|
|
41
|
+
|
|
42
|
+
// 开启深度计算
|
|
43
|
+
painter.enable(painter.DEPTH_TEST);
|
|
44
|
+
|
|
45
|
+
return painter
|
|
46
46
|
}
|