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,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
|