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