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.
Files changed (79) hide show
  1. package/CHANGELOG +212 -209
  2. package/README.md +136 -144
  3. package/lib/Buffer/index.umd.js +36 -36
  4. package/lib/Buffer/index.umd.min.js +2 -2
  5. package/lib/Canvas/index.umd.js +691 -691
  6. package/lib/Canvas/index.umd.min.js +2 -2
  7. package/lib/Cardinal/index.umd.js +91 -91
  8. package/lib/Cardinal/index.umd.min.js +2 -2
  9. package/lib/Eoap/index.umd.js +34 -34
  10. package/lib/Eoap/index.umd.min.js +2 -2
  11. package/lib/Geometry/index.umd.js +286 -286
  12. package/lib/Geometry/index.umd.min.js +2 -2
  13. package/lib/Hermite/index.umd.js +36 -36
  14. package/lib/Hermite/index.umd.min.js +2 -2
  15. package/lib/Matrix4/index.umd.js +125 -125
  16. package/lib/Matrix4/index.umd.min.js +2 -2
  17. package/lib/Mercator/index.umd.js +20 -20
  18. package/lib/Mercator/index.umd.min.js +2 -2
  19. package/lib/OralCanvas/index.es.js +634 -634
  20. package/lib/OralCanvas/index.es.min.js +2 -2
  21. package/lib/OralWebGL/index.es.js +552 -552
  22. package/lib/OralWebGL/index.es.min.js +2 -2
  23. package/lib/SVG/index.umd.js +471 -471
  24. package/lib/SVG/index.umd.min.js +2 -2
  25. package/lib/Shader/index.umd.js +61 -61
  26. package/lib/Shader/index.umd.min.js +2 -2
  27. package/lib/Texture/index.umd.js +54 -54
  28. package/lib/Texture/index.umd.min.js +2 -2
  29. package/lib/TreeLayout/index.umd.js +368 -368
  30. package/lib/TreeLayout/index.umd.min.js +2 -2
  31. package/lib/WebGL/index.umd.js +599 -599
  32. package/lib/WebGL/index.umd.min.js +2 -2
  33. package/lib/animation/index.umd.js +73 -73
  34. package/lib/animation/index.umd.min.js +2 -2
  35. package/lib/formatColor/index.umd.js +40 -40
  36. package/lib/formatColor/index.umd.min.js +2 -2
  37. package/lib/getLoopColors/index.umd.js +36 -36
  38. package/lib/getLoopColors/index.umd.min.js +2 -2
  39. package/lib/getWebGLContext/index.umd.js +63 -63
  40. package/lib/getWebGLContext/index.umd.min.js +2 -2
  41. package/lib/index.umd.js +2955 -2955
  42. package/lib/index.umd.min.js +2 -2
  43. package/lib/move/index.umd.js +8 -8
  44. package/lib/move/index.umd.min.js +2 -2
  45. package/lib/resizeObserver/index.umd.js +30 -30
  46. package/lib/resizeObserver/index.umd.min.js +2 -2
  47. package/lib/rotate/index.umd.js +8 -8
  48. package/lib/rotate/index.umd.min.js +2 -2
  49. package/lib/ruler/index.umd.js +138 -138
  50. package/lib/ruler/index.umd.min.js +2 -2
  51. package/lib/scale/index.umd.js +7 -7
  52. package/lib/scale/index.umd.min.js +2 -2
  53. package/lib/throttle/index.umd.js +49 -49
  54. package/lib/throttle/index.umd.min.js +2 -2
  55. package/lib/viewHandler/index.umd.js +120 -120
  56. package/lib/viewHandler/index.umd.min.js +2 -2
  57. package/miniprogram/ui-canvas/drawImage.js +34 -0
  58. package/miniprogram/ui-canvas/index.js +10 -2
  59. package/package/getWebGLContext/index.ts +40 -40
  60. package/package.json +70 -70
  61. package/src/Canvas.ts +72 -72
  62. package/src/Geometry.ts +210 -210
  63. package/src/WebGL.ts +66 -66
  64. package/src/common/canvas/index.ts +183 -183
  65. package/src/common/canvas/painter.ts +446 -446
  66. package/src/common/geometry/prism-horizontal.ts +50 -50
  67. package/src/common/geometry/prism-vertical.ts +55 -55
  68. package/src/common/geometry/tool/circle.ts +17 -17
  69. package/src/common/geometry/tool/rotateLine.ts +48 -48
  70. package/src/common/geometry/tool/triangles.ts +23 -23
  71. package/src/common/webgl/getWebGLContext.ts +45 -45
  72. package/src/common/webgl/index.ts +227 -227
  73. package/types/Canvas.d.ts +318 -318
  74. package/types/Geometry.d.ts +132 -132
  75. package/types/WebGLOption.d.ts +14 -14
  76. package/types/getWebGLContext.d.ts +4 -4
  77. package/types/ui-canvas.d.ts +4 -4
  78. package/uni-app/drawImage.js +17 -17
  79. package/uni-app/ui-canvas.vue +290 -290
@@ -1,228 +1,228 @@
1
- import type Object3DType from '../../../types/Object3D'
2
- import type Scene3DType from '../../../types/Scene3D'
3
- import type { WebGLmodeType } from "../../../types/getWebGLContext"
4
-
5
- import getWebGLContext from './getWebGLContext'
6
- import getColorFactory from './getColorFactory'
7
- import Matrix4 from '../../Matrix4/index'
8
- import doDraw from './doDraw'
9
- import assemble from '../assemble'
10
-
11
- // 获取区域信息前是否需要刷新区域
12
- let needUpdate = false
13
-
14
- const scale = 10
15
- class WebGL {
16
-
17
- readonly name: string = "WebGL"
18
-
19
- painter: WebGLRenderingContext
20
- private __regionPainter: WebGLRenderingContext
21
-
22
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
23
- private __getColor = (x: number, y: number) => "rgba(0,0,0,1)"
24
-
25
- private __regionList: {
26
- [key: string | number]: Array<number>
27
- } = {} //区域映射表
28
- private __regionAssemble = assemble(0, 1, 0.2, 3)
29
-
30
- private __regionName = "" // 当前绘制的内容名称
31
- private __regionColor = [0, 0, 0, 1] // 当前记录区域应该使用的颜色
32
-
33
- private __scene: Scene3DType = { // 记录着3D世界
34
- children: [],
35
-
36
- // 右手坐标系
37
- matrix: new Matrix4([
38
- 1, 0, 0, 0,
39
- 0, 1, 0, 0,
40
- 0, 0, 1, 0,
41
- 0, 0, 0, scale
42
- ])
43
- }
44
-
45
- private __proporion: number[]
46
-
47
- private __unique: number
48
-
49
- constructor(ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement | null, mode?: WebGLmodeType) {
50
- this.__unique = new Date().valueOf()
51
-
52
- this.painter = getWebGLContext(ViewCanvas, scale, {}, mode)
53
- if (RegionCanvas) {
54
- this.__regionPainter = getWebGLContext(RegionCanvas, scale, {
55
-
56
- // 如果不设置,涉及到缓冲区的情况可能无法获取颜色
57
- // preserveDrawingBuffer: true
58
- }, mode)
59
- }
60
-
61
- const proportion = this.painter.canvas.width / this.painter.canvas.height
62
-
63
- let xProportion = 1
64
- let yProportion = 1
65
-
66
- if (proportion > 1) {
67
- xProportion = 1 / proportion
68
- } else {
69
- yProportion = proportion
70
- }
71
-
72
- const zProportion = Math.min(xProportion, yProportion)
73
-
74
- this.__proporion = [
75
- xProportion, 0, 0, 0,
76
- 0, yProportion, 0, 0,
77
- 0, 0, zProportion, 0,
78
- 0, 0, 0, 1
79
- ]
80
-
81
- }
82
-
83
- matrix(initMatrix4?: number[]) {
84
- return new Matrix4(initMatrix4)
85
- }
86
-
87
- getMatrix() {
88
- return this.__scene.matrix
89
- }
90
-
91
- getObject3D() {
92
- return this.__scene.children
93
- }
94
-
95
- review(isUpdateRegion = false) {
96
-
97
- if (isUpdateRegion) {
98
- if (this.__regionPainter) {
99
- this.__regionPainter.clearColor(1, 1, 1, 1)
100
- this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT)
101
- }
102
- } else {
103
- this.painter.clearColor(1, 1, 1, 1)
104
- this.painter.clear(this.painter.COLOR_BUFFER_BIT)
105
- }
106
-
107
- for (let index = 0; index < this.__scene.children.length; index++) {
108
- this.draw(this.__scene.children[index], isUpdateRegion)
109
- }
110
- return this
111
- }
112
-
113
- private draw(object3D: Object3DType, isUpdateRegion = false) {
114
- if (!isUpdateRegion) needUpdate = true
115
-
116
- const meshWorld = {
117
- matrix: object3D.matrix?.value() as Array<number>
118
- }
119
-
120
- const globalWorld = {
121
- matrix: this.__scene.matrix.value(),
122
- proporion: this.__proporion
123
- }
124
-
125
- // 设置好当前区域
126
- this.setRegion(object3D.region)
127
-
128
- for (let index = 0; index < object3D.mesh.length; index++) {
129
-
130
- if (isUpdateRegion) {
131
- if (this.__regionPainter) {
132
- // 区域上
133
- doDraw("painter" + this.__unique, this.__regionPainter, {
134
- geometry: object3D.mesh[index].geometry,
135
- material: {
136
- color: {
137
- r: this.__regionColor[0],
138
- g: this.__regionColor[1],
139
- b: this.__regionColor[2],
140
- alpha: this.__regionColor[3]
141
- }
142
- }
143
- }, meshWorld, globalWorld)
144
-
145
- this.__getColor = getColorFactory(this.__regionPainter)
146
- }
147
- } else {
148
- // 画布上
149
- doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld)
150
- }
151
- }
152
-
153
- }
154
-
155
- render(object3D: Object3DType) {
156
- if (!('matrix' in object3D)) object3D.matrix = new Matrix4()
157
- if (!('region' in object3D)) object3D.region = ""
158
-
159
- // 对数据进行校对
160
- for (let index = 0; index < object3D.mesh.length; index++) {
161
- const mesh = object3D.mesh[index]
162
-
163
- if (mesh.geometry.attributes.normal && Array.isArray(mesh.geometry.attributes.normal.array)) {
164
- mesh.geometry.attributes.normal.array = new Float32Array(mesh.geometry.attributes.normal.array)
165
- }
166
-
167
- if (mesh.geometry.attributes.position && Array.isArray(mesh.geometry.attributes.position.array)) {
168
- mesh.geometry.attributes.position.array = new Float32Array(mesh.geometry.attributes.position.array)
169
- }
170
-
171
- if (mesh.geometry.attributes.uv && Array.isArray(mesh.geometry.attributes.uv.array)) {
172
- mesh.geometry.attributes.uv.array = new Float32Array(mesh.geometry.attributes.uv.array)
173
- }
174
-
175
- if (mesh.geometry.index && Array.isArray(mesh.geometry.index.array)) {
176
- mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array)
177
- }
178
-
179
- if (mesh.material.colors && Array.isArray(mesh.material.colors.array)) {
180
- mesh.material.colors.array = new Float32Array(mesh.material.colors.array)
181
- }
182
-
183
- }
184
-
185
- this.__scene.children.push(object3D)
186
- this.draw(object3D)
187
- }
188
-
189
- // 设置当前绘制区域名称
190
- setRegion(regionName: string | number | undefined) {
191
- this.__regionName = regionName + ""
192
-
193
- if (regionName) {
194
- if (this.__regionList[regionName] == void 0) {
195
- this.__regionList[regionName] = [... this.__regionAssemble(), 1]
196
- }
197
- this.__regionColor = this.__regionList[regionName]
198
- } else {
199
- this.__regionColor = [0, 0, 0, 1]
200
- }
201
- return this
202
- }
203
-
204
- // 获取当前事件触发的区域名称
205
- getRegion(x: number, y: number): Promise<string> {
206
- if (needUpdate) this.review(true)
207
-
208
- needUpdate = false
209
- return new Promise((resolve) => {
210
-
211
- const rgba = this.__getColor(x, y)
212
-
213
- // 查找当前点击的区域
214
- for (const key in this.__regionList) {
215
- const currentRGBA = this.__regionList[key]
216
- if ("rgba(" + currentRGBA[0] * 255 + "," + currentRGBA[1] * 255 + "," + currentRGBA[2] * 255 + "," + currentRGBA[3] * 255 + ")" == rgba) {
217
- resolve(key)
218
- break
219
- }
220
- }
221
- resolve("")
222
-
223
- })
224
- }
225
-
226
- }
227
-
1
+ import type Object3DType from '../../../types/Object3D'
2
+ import type Scene3DType from '../../../types/Scene3D'
3
+ import type { WebGLmodeType } from "../../../types/getWebGLContext"
4
+
5
+ import getWebGLContext from './getWebGLContext'
6
+ import getColorFactory from './getColorFactory'
7
+ import Matrix4 from '../../Matrix4/index'
8
+ import doDraw from './doDraw'
9
+ import assemble from '../assemble'
10
+
11
+ // 获取区域信息前是否需要刷新区域
12
+ let needUpdate = false
13
+
14
+ const scale = 10
15
+ class WebGL {
16
+
17
+ readonly name: string = "WebGL"
18
+
19
+ painter: WebGLRenderingContext
20
+ private __regionPainter: WebGLRenderingContext
21
+
22
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
23
+ private __getColor = (x: number, y: number) => "rgba(0,0,0,1)"
24
+
25
+ private __regionList: {
26
+ [key: string | number]: Array<number>
27
+ } = {} //区域映射表
28
+ private __regionAssemble = assemble(0, 1, 0.2, 3)
29
+
30
+ private __regionName = "" // 当前绘制的内容名称
31
+ private __regionColor = [0, 0, 0, 1] // 当前记录区域应该使用的颜色
32
+
33
+ private __scene: Scene3DType = { // 记录着3D世界
34
+ children: [],
35
+
36
+ // 右手坐标系
37
+ matrix: new Matrix4([
38
+ 1, 0, 0, 0,
39
+ 0, 1, 0, 0,
40
+ 0, 0, 1, 0,
41
+ 0, 0, 0, scale
42
+ ])
43
+ }
44
+
45
+ private __proporion: number[]
46
+
47
+ private __unique: number
48
+
49
+ constructor(ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement | null, mode?: WebGLmodeType) {
50
+ this.__unique = new Date().valueOf()
51
+
52
+ this.painter = getWebGLContext(ViewCanvas, scale, {}, mode)
53
+ if (RegionCanvas) {
54
+ this.__regionPainter = getWebGLContext(RegionCanvas, scale, {
55
+
56
+ // 如果不设置,涉及到缓冲区的情况可能无法获取颜色
57
+ // preserveDrawingBuffer: true
58
+ }, mode)
59
+ }
60
+
61
+ const proportion = this.painter.canvas.width / this.painter.canvas.height
62
+
63
+ let xProportion = 1
64
+ let yProportion = 1
65
+
66
+ if (proportion > 1) {
67
+ xProportion = 1 / proportion
68
+ } else {
69
+ yProportion = proportion
70
+ }
71
+
72
+ const zProportion = Math.min(xProportion, yProportion)
73
+
74
+ this.__proporion = [
75
+ xProportion, 0, 0, 0,
76
+ 0, yProportion, 0, 0,
77
+ 0, 0, zProportion, 0,
78
+ 0, 0, 0, 1
79
+ ]
80
+
81
+ }
82
+
83
+ matrix(initMatrix4?: number[]) {
84
+ return new Matrix4(initMatrix4)
85
+ }
86
+
87
+ getMatrix() {
88
+ return this.__scene.matrix
89
+ }
90
+
91
+ getObject3D() {
92
+ return this.__scene.children
93
+ }
94
+
95
+ review(isUpdateRegion = false) {
96
+
97
+ if (isUpdateRegion) {
98
+ if (this.__regionPainter) {
99
+ this.__regionPainter.clearColor(1, 1, 1, 1)
100
+ this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT)
101
+ }
102
+ } else {
103
+ this.painter.clearColor(1, 1, 1, 1)
104
+ this.painter.clear(this.painter.COLOR_BUFFER_BIT)
105
+ }
106
+
107
+ for (let index = 0; index < this.__scene.children.length; index++) {
108
+ this.draw(this.__scene.children[index], isUpdateRegion)
109
+ }
110
+ return this
111
+ }
112
+
113
+ private draw(object3D: Object3DType, isUpdateRegion = false) {
114
+ if (!isUpdateRegion) needUpdate = true
115
+
116
+ const meshWorld = {
117
+ matrix: object3D.matrix?.value() as Array<number>
118
+ }
119
+
120
+ const globalWorld = {
121
+ matrix: this.__scene.matrix.value(),
122
+ proporion: this.__proporion
123
+ }
124
+
125
+ // 设置好当前区域
126
+ this.setRegion(object3D.region)
127
+
128
+ for (let index = 0; index < object3D.mesh.length; index++) {
129
+
130
+ if (isUpdateRegion) {
131
+ if (this.__regionPainter) {
132
+ // 区域上
133
+ doDraw("painter" + this.__unique, this.__regionPainter, {
134
+ geometry: object3D.mesh[index].geometry,
135
+ material: {
136
+ color: {
137
+ r: this.__regionColor[0],
138
+ g: this.__regionColor[1],
139
+ b: this.__regionColor[2],
140
+ alpha: this.__regionColor[3]
141
+ }
142
+ }
143
+ }, meshWorld, globalWorld)
144
+
145
+ this.__getColor = getColorFactory(this.__regionPainter)
146
+ }
147
+ } else {
148
+ // 画布上
149
+ doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld)
150
+ }
151
+ }
152
+
153
+ }
154
+
155
+ render(object3D: Object3DType) {
156
+ if (!('matrix' in object3D)) object3D.matrix = new Matrix4()
157
+ if (!('region' in object3D)) object3D.region = ""
158
+
159
+ // 对数据进行校对
160
+ for (let index = 0; index < object3D.mesh.length; index++) {
161
+ const mesh = object3D.mesh[index]
162
+
163
+ if (mesh.geometry.attributes.normal && Array.isArray(mesh.geometry.attributes.normal.array)) {
164
+ mesh.geometry.attributes.normal.array = new Float32Array(mesh.geometry.attributes.normal.array)
165
+ }
166
+
167
+ if (mesh.geometry.attributes.position && Array.isArray(mesh.geometry.attributes.position.array)) {
168
+ mesh.geometry.attributes.position.array = new Float32Array(mesh.geometry.attributes.position.array)
169
+ }
170
+
171
+ if (mesh.geometry.attributes.uv && Array.isArray(mesh.geometry.attributes.uv.array)) {
172
+ mesh.geometry.attributes.uv.array = new Float32Array(mesh.geometry.attributes.uv.array)
173
+ }
174
+
175
+ if (mesh.geometry.index && Array.isArray(mesh.geometry.index.array)) {
176
+ mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array)
177
+ }
178
+
179
+ if (mesh.material.colors && Array.isArray(mesh.material.colors.array)) {
180
+ mesh.material.colors.array = new Float32Array(mesh.material.colors.array)
181
+ }
182
+
183
+ }
184
+
185
+ this.__scene.children.push(object3D)
186
+ this.draw(object3D)
187
+ }
188
+
189
+ // 设置当前绘制区域名称
190
+ setRegion(regionName: string | number | undefined) {
191
+ this.__regionName = regionName + ""
192
+
193
+ if (regionName) {
194
+ if (this.__regionList[regionName] == void 0) {
195
+ this.__regionList[regionName] = [... this.__regionAssemble(), 1]
196
+ }
197
+ this.__regionColor = this.__regionList[regionName]
198
+ } else {
199
+ this.__regionColor = [0, 0, 0, 1]
200
+ }
201
+ return this
202
+ }
203
+
204
+ // 获取当前事件触发的区域名称
205
+ getRegion(x: number, y: number): Promise<string> {
206
+ if (needUpdate) this.review(true)
207
+
208
+ needUpdate = false
209
+ return new Promise((resolve) => {
210
+
211
+ const rgba = this.__getColor(x, y)
212
+
213
+ // 查找当前点击的区域
214
+ for (const key in this.__regionList) {
215
+ const currentRGBA = this.__regionList[key]
216
+ if ("rgba(" + currentRGBA[0] * 255 + "," + currentRGBA[1] * 255 + "," + currentRGBA[2] * 255 + "," + currentRGBA[3] * 255 + ")" == rgba) {
217
+ resolve(key)
218
+ break
219
+ }
220
+ }
221
+ resolve("")
222
+
223
+ })
224
+ }
225
+
226
+ }
227
+
228
228
  export default WebGL