vislite 0.7.0 → 0.7.1
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 +11 -1
- package/README.md +135 -135
- package/lib/Buffer/index.umd.js +2 -2
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +19 -13
- 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 +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 +11 -7
- package/lib/OralCanvas/index.es.min.js +3 -3
- package/lib/OralWebGL/index.es.js +2 -3
- 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 +2 -3
- 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 +2 -2
- package/lib/TreeLayout/index.umd.min.js +2 -2
- package/lib/WebGL/index.umd.js +2 -3
- 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 +2 -2
- package/lib/getWebGLContext/index.umd.min.js +2 -2
- package/lib/index.umd.js +19 -14
- 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 +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 +8 -6
- package/src/Geometry.ts +0 -1
- package/src/Matrix4/rotate.ts +15 -15
- package/src/Matrix4/transform.ts +64 -64
- package/src/WebGL.ts +66 -66
- package/src/common/assemble.ts +22 -22
- package/src/common/canvas/index.ts +10 -4
- package/src/common/canvas/painter.ts +1 -1
- package/src/common/geometry/prism-vertical.ts +40 -40
- package/src/common/geometry/tool/rotateLine.ts +35 -35
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +190 -190
- package/src/common/svg/index.ts +356 -356
- package/src/common/svg/tool.ts +44 -44
- package/src/common/tree/toInnerTree.ts +59 -59
- 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/getWebGLContext.ts +28 -28
- package/src/common/webgl/index.ts +226 -226
- package/src/common/webgl/shader.ts +1 -1
- package/src/common/webgl/texture.ts +97 -97
- package/src/layout/TreeLayout.ts +188 -188
- package/src/resizeObserver.ts +37 -37
- package/src/ruler.ts +209 -209
- package/src/viewHandler.ts +160 -160
- package/types/Canvas.d.ts +308 -308
- package/types/Geometry.d.ts +65 -65
- package/types/Object3D.d.ts +114 -114
- package/types/SVGConfig.d.ts +79 -79
- package/types/Shader.d.ts +23 -21
- package/types/TreeConfig.d.ts +36 -36
- package/uni-app/ui-canvas.vue +53 -9
package/src/Matrix4/transform.ts
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 针对任意射线(a1,b1,c1)->(a2,b2,c2)
|
|
3
|
-
* 计算出两个变换矩阵
|
|
4
|
-
* 分别为:任意射线变成OZ轴变换矩阵 + OZ轴变回原来的射线的变换矩阵
|
|
5
|
-
*/
|
|
6
|
-
export default function (a1: number, b1: number, c1?: number, a2?: number, b2?: number, c2?: number) {
|
|
7
|
-
|
|
8
|
-
if (typeof a1 === 'number' && typeof b1 === 'number') {
|
|
9
|
-
|
|
10
|
-
// 如果设置两个点
|
|
11
|
-
// 表示二维上围绕某个点旋转
|
|
12
|
-
if (typeof c1 !== 'number') {
|
|
13
|
-
c1 = 0
|
|
14
|
-
a2 = a1
|
|
15
|
-
b2 = b1
|
|
16
|
-
c2 = 1
|
|
17
|
-
}
|
|
18
|
-
// 只设置三个点(设置不足六个点都认为只设置了三个点)
|
|
19
|
-
// 表示围绕从原点出发的射线旋转
|
|
20
|
-
else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
|
|
21
|
-
a2 = a1
|
|
22
|
-
b2 = b1
|
|
23
|
-
c2 = c1
|
|
24
|
-
a1 = 0
|
|
25
|
-
b1 = 0
|
|
26
|
-
c1 = 0
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (a1 == a2 && b1 == b2 && c1 == c2) throw new Error('It\'s not a legitimate ray!')
|
|
30
|
-
|
|
31
|
-
const sqrt1 = Math.sqrt((a2 - a1) * (a2 - a1) + (b2 - b1) * (b2 - b1)),
|
|
32
|
-
cos1 = sqrt1 != 0 ? (b2 - b1) / sqrt1 : 1,
|
|
33
|
-
sin1 = sqrt1 != 0 ? (a2 - a1) / sqrt1 : 0,
|
|
34
|
-
|
|
35
|
-
b = (a2 - a1) * sin1 + (b2 - b1) * cos1,
|
|
36
|
-
c = c2 - c1,
|
|
37
|
-
|
|
38
|
-
sqrt2 = Math.sqrt(b * b + c * c),
|
|
39
|
-
cos2 = sqrt2 != 0 ? c / sqrt2 : 1,
|
|
40
|
-
sin2 = sqrt2 != 0 ? b / sqrt2 : 0
|
|
41
|
-
|
|
42
|
-
return [
|
|
43
|
-
|
|
44
|
-
// 任意射线变成OZ轴变换矩阵
|
|
45
|
-
[
|
|
46
|
-
cos1, cos2 * sin1, sin1 * sin2, 0,
|
|
47
|
-
-sin1, cos1 * cos2, cos1 * sin2, 0,
|
|
48
|
-
0, -sin2, cos2, 0,
|
|
49
|
-
b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
|
|
50
|
-
],
|
|
51
|
-
|
|
52
|
-
// OZ轴变回原来的射线的变换矩阵
|
|
53
|
-
[
|
|
54
|
-
cos1, -sin1, 0, 0,
|
|
55
|
-
cos2 * sin1, cos2 * cos1, -sin2, 0,
|
|
56
|
-
sin1 * sin2, cos1 * sin2, cos2, 0,
|
|
57
|
-
a1, b1, c1, 1
|
|
58
|
-
]
|
|
59
|
-
|
|
60
|
-
]
|
|
61
|
-
} else {
|
|
62
|
-
throw new Error('a1 and b1 is required!')
|
|
63
|
-
}
|
|
64
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 针对任意射线(a1,b1,c1)->(a2,b2,c2)
|
|
3
|
+
* 计算出两个变换矩阵
|
|
4
|
+
* 分别为:任意射线变成OZ轴变换矩阵 + OZ轴变回原来的射线的变换矩阵
|
|
5
|
+
*/
|
|
6
|
+
export default function (a1: number, b1: number, c1?: number, a2?: number, b2?: number, c2?: number) {
|
|
7
|
+
|
|
8
|
+
if (typeof a1 === 'number' && typeof b1 === 'number') {
|
|
9
|
+
|
|
10
|
+
// 如果设置两个点
|
|
11
|
+
// 表示二维上围绕某个点旋转
|
|
12
|
+
if (typeof c1 !== 'number') {
|
|
13
|
+
c1 = 0
|
|
14
|
+
a2 = a1
|
|
15
|
+
b2 = b1
|
|
16
|
+
c2 = 1
|
|
17
|
+
}
|
|
18
|
+
// 只设置三个点(设置不足六个点都认为只设置了三个点)
|
|
19
|
+
// 表示围绕从原点出发的射线旋转
|
|
20
|
+
else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
|
|
21
|
+
a2 = a1
|
|
22
|
+
b2 = b1
|
|
23
|
+
c2 = c1
|
|
24
|
+
a1 = 0
|
|
25
|
+
b1 = 0
|
|
26
|
+
c1 = 0
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (a1 == a2 && b1 == b2 && c1 == c2) throw new Error('It\'s not a legitimate ray!')
|
|
30
|
+
|
|
31
|
+
const sqrt1 = Math.sqrt((a2 - a1) * (a2 - a1) + (b2 - b1) * (b2 - b1)),
|
|
32
|
+
cos1 = sqrt1 != 0 ? (b2 - b1) / sqrt1 : 1,
|
|
33
|
+
sin1 = sqrt1 != 0 ? (a2 - a1) / sqrt1 : 0,
|
|
34
|
+
|
|
35
|
+
b = (a2 - a1) * sin1 + (b2 - b1) * cos1,
|
|
36
|
+
c = c2 - c1,
|
|
37
|
+
|
|
38
|
+
sqrt2 = Math.sqrt(b * b + c * c),
|
|
39
|
+
cos2 = sqrt2 != 0 ? c / sqrt2 : 1,
|
|
40
|
+
sin2 = sqrt2 != 0 ? b / sqrt2 : 0
|
|
41
|
+
|
|
42
|
+
return [
|
|
43
|
+
|
|
44
|
+
// 任意射线变成OZ轴变换矩阵
|
|
45
|
+
[
|
|
46
|
+
cos1, cos2 * sin1, sin1 * sin2, 0,
|
|
47
|
+
-sin1, cos1 * cos2, cos1 * sin2, 0,
|
|
48
|
+
0, -sin2, cos2, 0,
|
|
49
|
+
b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
|
|
50
|
+
],
|
|
51
|
+
|
|
52
|
+
// OZ轴变回原来的射线的变换矩阵
|
|
53
|
+
[
|
|
54
|
+
cos1, -sin1, 0, 0,
|
|
55
|
+
cos2 * sin1, cos2 * cos1, -sin2, 0,
|
|
56
|
+
sin1 * sin2, cos1 * sin2, cos2, 0,
|
|
57
|
+
a1, b1, c1, 1
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
]
|
|
61
|
+
} else {
|
|
62
|
+
throw new Error('a1 and b1 is required!')
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/WebGL.ts
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import type WebGLOptionType from '../types/WebGLOption'
|
|
2
|
-
import type WebGLType from '../types/WebGL'
|
|
3
|
-
|
|
4
|
-
import OralWebGL from './common/webgl/index'
|
|
5
|
-
import mergeOption from './common/mergeOption'
|
|
6
|
-
|
|
7
|
-
class WebGL extends OralWebGL implements WebGLType {
|
|
8
|
-
constructor(el: HTMLElement | null, option: WebGLOptionType = {}) {
|
|
9
|
-
if (!el) {
|
|
10
|
-
throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.")
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
option = mergeOption(option, {
|
|
14
|
-
region: true
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
const width = el.clientWidth, height = el.clientHeight
|
|
18
|
-
|
|
19
|
-
let ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement | null = null
|
|
20
|
-
|
|
21
|
-
const _el = el as any
|
|
22
|
-
|
|
23
|
-
// 如果已经初始化过了
|
|
24
|
-
if (_el._vislite_canvas_) {
|
|
25
|
-
ViewCanvas = _el._vislite_canvas_[0]
|
|
26
|
-
RegionCanvas = _el._vislite_canvas_[1]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// 否则就初始化
|
|
30
|
-
else {
|
|
31
|
-
|
|
32
|
-
if (option.region) {
|
|
33
|
-
|
|
34
|
-
RegionCanvas = document.createElement('canvas')
|
|
35
|
-
el.appendChild(RegionCanvas)
|
|
36
|
-
|
|
37
|
-
RegionCanvas.style.position = 'absolute'
|
|
38
|
-
RegionCanvas.style.zIndex = "-1"
|
|
39
|
-
RegionCanvas.style.opacity = "0"
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
ViewCanvas = document.createElement('canvas')
|
|
44
|
-
el.appendChild(ViewCanvas)
|
|
45
|
-
|
|
46
|
-
_el._vislite_canvas_ = [ViewCanvas, RegionCanvas]
|
|
47
|
-
|
|
48
|
-
el.setAttribute('vislite', 'WebGL')
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 设置画布大小
|
|
52
|
-
for (const canvas of [ViewCanvas, RegionCanvas]) {
|
|
53
|
-
|
|
54
|
-
if (canvas) {
|
|
55
|
-
canvas.style.width = width + "px"
|
|
56
|
-
canvas.setAttribute('width', width + "")
|
|
57
|
-
|
|
58
|
-
canvas.style.height = height + "px"
|
|
59
|
-
canvas.setAttribute('height', height + "")
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
super(ViewCanvas, RegionCanvas)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
1
|
+
import type WebGLOptionType from '../types/WebGLOption'
|
|
2
|
+
import type WebGLType from '../types/WebGL'
|
|
3
|
+
|
|
4
|
+
import OralWebGL from './common/webgl/index'
|
|
5
|
+
import mergeOption from './common/mergeOption'
|
|
6
|
+
|
|
7
|
+
class WebGL extends OralWebGL implements WebGLType {
|
|
8
|
+
constructor(el: HTMLElement | null, option: WebGLOptionType = {}) {
|
|
9
|
+
if (!el) {
|
|
10
|
+
throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.")
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
option = mergeOption(option, {
|
|
14
|
+
region: true
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const width = el.clientWidth, height = el.clientHeight
|
|
18
|
+
|
|
19
|
+
let ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement | null = null
|
|
20
|
+
|
|
21
|
+
const _el = el as any
|
|
22
|
+
|
|
23
|
+
// 如果已经初始化过了
|
|
24
|
+
if (_el._vislite_canvas_) {
|
|
25
|
+
ViewCanvas = _el._vislite_canvas_[0]
|
|
26
|
+
RegionCanvas = _el._vislite_canvas_[1]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 否则就初始化
|
|
30
|
+
else {
|
|
31
|
+
|
|
32
|
+
if (option.region) {
|
|
33
|
+
|
|
34
|
+
RegionCanvas = document.createElement('canvas')
|
|
35
|
+
el.appendChild(RegionCanvas)
|
|
36
|
+
|
|
37
|
+
RegionCanvas.style.position = 'absolute'
|
|
38
|
+
RegionCanvas.style.zIndex = "-1"
|
|
39
|
+
RegionCanvas.style.opacity = "0"
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
ViewCanvas = document.createElement('canvas')
|
|
44
|
+
el.appendChild(ViewCanvas)
|
|
45
|
+
|
|
46
|
+
_el._vislite_canvas_ = [ViewCanvas, RegionCanvas]
|
|
47
|
+
|
|
48
|
+
el.setAttribute('vislite', 'WebGL')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 设置画布大小
|
|
52
|
+
for (const canvas of [ViewCanvas, RegionCanvas]) {
|
|
53
|
+
|
|
54
|
+
if (canvas) {
|
|
55
|
+
canvas.style.width = width + "px"
|
|
56
|
+
canvas.setAttribute('width', width + "")
|
|
57
|
+
|
|
58
|
+
canvas.style.height = height + "px"
|
|
59
|
+
canvas.setAttribute('height', height + "")
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
super(ViewCanvas, RegionCanvas)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
67
|
export default WebGL
|
package/src/common/assemble.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export default function (begin: number, end: number, step: number, count: number) {
|
|
2
|
-
const val: Array<number> = []
|
|
3
|
-
for (let index = 0; index < count; index++) val[index] = begin
|
|
4
|
-
|
|
5
|
-
// 非常类似进制数,每次调用都+1
|
|
6
|
-
return function () {
|
|
7
|
-
for (let i = 0; i < count; i++) {
|
|
8
|
-
|
|
9
|
-
// 如果当前位可以进1
|
|
10
|
-
if (val[i] + step < end) {
|
|
11
|
-
val[i] = +(val[i] + step).toFixed(7)
|
|
12
|
-
break
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// 如果当前位不可以,那当前位归0,尝试下一位
|
|
16
|
-
else if (i < count - 1) {
|
|
17
|
-
val[i] = begin
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return val
|
|
22
|
-
}
|
|
1
|
+
export default function (begin: number, end: number, step: number, count: number) {
|
|
2
|
+
const val: Array<number> = []
|
|
3
|
+
for (let index = 0; index < count; index++) val[index] = begin
|
|
4
|
+
|
|
5
|
+
// 非常类似进制数,每次调用都+1
|
|
6
|
+
return function () {
|
|
7
|
+
for (let i = 0; i < count; i++) {
|
|
8
|
+
|
|
9
|
+
// 如果当前位可以进1
|
|
10
|
+
if (val[i] + step < end) {
|
|
11
|
+
val[i] = +(val[i] + step).toFixed(7)
|
|
12
|
+
break
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// 如果当前位不可以,那当前位归0,尝试下一位
|
|
16
|
+
else if (i < count - 1) {
|
|
17
|
+
val[i] = begin
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return val
|
|
22
|
+
}
|
|
23
23
|
}
|
|
@@ -20,20 +20,24 @@ class Canvas extends PainterRender {
|
|
|
20
20
|
readonly name: string = "Canvas"
|
|
21
21
|
|
|
22
22
|
private __regionList = {} //区域映射表
|
|
23
|
+
private __scaleSize
|
|
23
24
|
|
|
24
25
|
// 步长由1改为10是为了优化区域计算有时候出错问题
|
|
25
26
|
// 2023年7月6日 于南京
|
|
26
27
|
private __regionAssemble = assemble(0, 255, 10, 3)
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
// 添加scaleSize参数是为了适配画布缩放后的处理
|
|
30
|
+
// 2024年1月17日 于南京
|
|
31
|
+
constructor(ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement | null, opts: CanvasOptsType = {}, scaleSize = 1) {
|
|
29
32
|
super(
|
|
30
33
|
ViewCanvas,
|
|
31
34
|
opts,
|
|
32
35
|
RegionCanvas ? new PainterRender(RegionCanvas, {
|
|
33
36
|
willReadFrequently: true,
|
|
34
|
-
}) : undefined, true
|
|
37
|
+
}) : undefined, true, scaleSize
|
|
35
38
|
)
|
|
36
39
|
|
|
40
|
+
this.__scaleSize = scaleSize
|
|
37
41
|
this.setRegion("")
|
|
38
42
|
}
|
|
39
43
|
|
|
@@ -142,8 +146,8 @@ class Canvas extends PainterRender {
|
|
|
142
146
|
// 获取画布信息
|
|
143
147
|
getInfo() {
|
|
144
148
|
return {
|
|
145
|
-
width: this.painter.canvas.width,
|
|
146
|
-
height: this.painter.canvas.height
|
|
149
|
+
width: this.painter.canvas.width / this.__scaleSize,
|
|
150
|
+
height: this.painter.canvas.height / this.__scaleSize
|
|
147
151
|
}
|
|
148
152
|
}
|
|
149
153
|
|
|
@@ -159,6 +163,8 @@ class Canvas extends PainterRender {
|
|
|
159
163
|
|
|
160
164
|
// 获取指定位置颜色
|
|
161
165
|
getColor(x: number, y: number) {
|
|
166
|
+
x *= this.__scaleSize
|
|
167
|
+
y *= this.__scaleSize
|
|
162
168
|
const currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data
|
|
163
169
|
return (
|
|
164
170
|
"rgba(" +
|
|
@@ -65,7 +65,7 @@ class Painter {
|
|
|
65
65
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
constructor(canvas: HTMLCanvasElement, opts: CanvasOptsType = {}, region?: Painter, isPainter = false) {
|
|
68
|
+
constructor(canvas: HTMLCanvasElement, opts: CanvasOptsType = {}, region?: Painter, isPainter = false, scaleSize = 1) {
|
|
69
69
|
this.painter = canvas.getContext("2d", opts) as CanvasRenderingContext2D
|
|
70
70
|
this.__region = region
|
|
71
71
|
this.__isPainter = isPainter
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import rotate from '../../rotate'
|
|
2
|
-
|
|
3
|
-
// 棱柱垂直部分
|
|
4
|
-
|
|
5
|
-
export default function (normal: boolean, x: number, y: number, z: number, radius: number, height: number, num: number) {
|
|
6
|
-
const points = []
|
|
7
|
-
let beginPosition: [number, number]
|
|
8
|
-
|
|
9
|
-
if (num == 4) {
|
|
10
|
-
beginPosition = rotate(x, z, Math.PI * 0.25, x - radius, z)
|
|
11
|
-
} else {
|
|
12
|
-
beginPosition = [x + radius, z]
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const deg = Math.PI * 2 / num, degHalf = Math.PI * 2 / (num * 2)
|
|
16
|
-
|
|
17
|
-
let endPosition: [number, number], normalPosition: [number, number, number] | [] = []
|
|
18
|
-
for (let i = 0; i < num; i++) {
|
|
19
|
-
|
|
20
|
-
endPosition = rotate(x, z, deg, ...beginPosition)
|
|
21
|
-
|
|
22
|
-
if (normal) {
|
|
23
|
-
const halfPosition = rotate(x, z, degHalf, ...beginPosition)
|
|
24
|
-
normalPosition = [halfPosition[0], 0, halfPosition[1]]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
|
|
28
|
-
points.push(beginPosition[0], y + height, beginPosition[1], ...normalPosition)
|
|
29
|
-
points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
|
|
30
|
-
|
|
31
|
-
points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
|
|
32
|
-
points.push(endPosition[0], y, endPosition[1], ...normalPosition)
|
|
33
|
-
points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
beginPosition = endPosition
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return points
|
|
40
|
-
}
|
|
1
|
+
import rotate from '../../rotate'
|
|
2
|
+
|
|
3
|
+
// 棱柱垂直部分
|
|
4
|
+
|
|
5
|
+
export default function (normal: boolean, x: number, y: number, z: number, radius: number, height: number, num: number) {
|
|
6
|
+
const points = []
|
|
7
|
+
let beginPosition: [number, number]
|
|
8
|
+
|
|
9
|
+
if (num == 4) {
|
|
10
|
+
beginPosition = rotate(x, z, Math.PI * 0.25, x - radius, z)
|
|
11
|
+
} else {
|
|
12
|
+
beginPosition = [x + radius, z]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const deg = Math.PI * 2 / num, degHalf = Math.PI * 2 / (num * 2)
|
|
16
|
+
|
|
17
|
+
let endPosition: [number, number], normalPosition: [number, number, number] | [] = []
|
|
18
|
+
for (let i = 0; i < num; i++) {
|
|
19
|
+
|
|
20
|
+
endPosition = rotate(x, z, deg, ...beginPosition)
|
|
21
|
+
|
|
22
|
+
if (normal) {
|
|
23
|
+
const halfPosition = rotate(x, z, degHalf, ...beginPosition)
|
|
24
|
+
normalPosition = [halfPosition[0], 0, halfPosition[1]]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
|
|
28
|
+
points.push(beginPosition[0], y + height, beginPosition[1], ...normalPosition)
|
|
29
|
+
points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
|
|
30
|
+
|
|
31
|
+
points.push(beginPosition[0], y, beginPosition[1], ...normalPosition)
|
|
32
|
+
points.push(endPosition[0], y, endPosition[1], ...normalPosition)
|
|
33
|
+
points.push(endPosition[0], y + height, endPosition[1], ...normalPosition)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
beginPosition = endPosition
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return points
|
|
40
|
+
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
export default function (x: number, y: number, z: number, x2: number, y2: number, z2: number) {
|
|
2
|
-
return (x0: number, y0: number, z0: number, isNormal: boolean) => {
|
|
3
|
-
let sin: number, cos: number, temp: Array<number>
|
|
4
|
-
|
|
5
|
-
// 第一步:归零化
|
|
6
|
-
let _x0 = x0 - (isNormal ? 0 : x), _y0 = y0 - (isNormal ? 0 : y), _z0 = z0 - (isNormal ? 0 : z) // 法向量起点本来就是原点
|
|
7
|
-
const _x2 = x2 - x, _y2 = y2 - y, _z2 = z2 - z
|
|
8
|
-
|
|
9
|
-
// 第二步:围绕OZ轴旋转
|
|
10
|
-
|
|
11
|
-
const __d = Math.sqrt(_x2 * _x2 + _z2 * _z2)
|
|
12
|
-
cos = _x2 / __d
|
|
13
|
-
sin = _z2 / __d
|
|
14
|
-
|
|
15
|
-
const _x2N = _z2 * sin + _x2 * cos
|
|
16
|
-
|
|
17
|
-
const d = Math.sqrt(_y2 * _y2 + _x2N * _x2N)
|
|
18
|
-
cos = _y2 / d
|
|
19
|
-
sin = _x2N / d
|
|
20
|
-
|
|
21
|
-
temp = [_y0, _x0]
|
|
22
|
-
_y0 = temp[0] * cos - temp[1] * sin
|
|
23
|
-
_x0 = temp[0] * sin + temp[1] * cos
|
|
24
|
-
|
|
25
|
-
// 第三步:围绕0Y轴旋转
|
|
26
|
-
cos = _x2 / __d
|
|
27
|
-
sin = _z2 / __d
|
|
28
|
-
|
|
29
|
-
temp = [_x0, _z0]
|
|
30
|
-
_x0 = temp[0] * cos - temp[1] * sin
|
|
31
|
-
_z0 = temp[0] * sin + temp[1] * cos
|
|
32
|
-
|
|
33
|
-
// 第四步:去零化(直接返回)
|
|
34
|
-
return [_x0 + (isNormal ? 0 : x), _y0 + (isNormal ? 0 : y), _z0 + (isNormal ? 0 : z)]
|
|
35
|
-
}
|
|
1
|
+
export default function (x: number, y: number, z: number, x2: number, y2: number, z2: number) {
|
|
2
|
+
return (x0: number, y0: number, z0: number, isNormal: boolean) => {
|
|
3
|
+
let sin: number, cos: number, temp: Array<number>
|
|
4
|
+
|
|
5
|
+
// 第一步:归零化
|
|
6
|
+
let _x0 = x0 - (isNormal ? 0 : x), _y0 = y0 - (isNormal ? 0 : y), _z0 = z0 - (isNormal ? 0 : z) // 法向量起点本来就是原点
|
|
7
|
+
const _x2 = x2 - x, _y2 = y2 - y, _z2 = z2 - z
|
|
8
|
+
|
|
9
|
+
// 第二步:围绕OZ轴旋转
|
|
10
|
+
|
|
11
|
+
const __d = Math.sqrt(_x2 * _x2 + _z2 * _z2)
|
|
12
|
+
cos = _x2 / __d
|
|
13
|
+
sin = _z2 / __d
|
|
14
|
+
|
|
15
|
+
const _x2N = _z2 * sin + _x2 * cos
|
|
16
|
+
|
|
17
|
+
const d = Math.sqrt(_y2 * _y2 + _x2N * _x2N)
|
|
18
|
+
cos = _y2 / d
|
|
19
|
+
sin = _x2N / d
|
|
20
|
+
|
|
21
|
+
temp = [_y0, _x0]
|
|
22
|
+
_y0 = temp[0] * cos - temp[1] * sin
|
|
23
|
+
_x0 = temp[0] * sin + temp[1] * cos
|
|
24
|
+
|
|
25
|
+
// 第三步:围绕0Y轴旋转
|
|
26
|
+
cos = _x2 / __d
|
|
27
|
+
sin = _z2 / __d
|
|
28
|
+
|
|
29
|
+
temp = [_x0, _z0]
|
|
30
|
+
_x0 = temp[0] * cos - temp[1] * sin
|
|
31
|
+
_z0 = temp[0] * sin + temp[1] * cos
|
|
32
|
+
|
|
33
|
+
// 第四步:去零化(直接返回)
|
|
34
|
+
return [_x0 + (isNormal ? 0 : x), _y0 + (isNormal ? 0 : y), _z0 + (isNormal ? 0 : z)]
|
|
35
|
+
}
|
|
36
36
|
}
|
package/src/common/setStyle.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// 修改样式
|
|
2
|
-
export default function (el: HTMLElement | SVGElement, styles: any) {
|
|
3
|
-
for (const key in styles) {
|
|
4
|
-
el.style[key as any] = styles[key]
|
|
5
|
-
}
|
|
1
|
+
// 修改样式
|
|
2
|
+
export default function (el: HTMLElement | SVGElement, styles: any) {
|
|
3
|
+
for (const key in styles) {
|
|
4
|
+
el.style[key as any] = styles[key]
|
|
5
|
+
}
|
|
6
6
|
}
|