vislite 0.8.0 → 1.0.0-next.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/AUTHORS.txt +6 -6
- package/CHANGELOG +18 -2
- package/LICENSE +20 -20
- package/README.md +2 -36
- package/lib/Buffer/index.umd.js +2 -2
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +9 -24
- 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/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/SVG/index.umd.js +19 -35
- package/lib/SVG/index.umd.min.js +3 -3
- package/lib/Shader/index.umd.js +3 -82
- 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/animation/index.umd.js +2 -2
- package/lib/animation/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 +104 -975
- 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/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/miniprogram/ui-canvas/index.js +100 -107
- package/miniprogram/ui-canvas/index.json +4 -4
- package/miniprogram/ui-canvas/index.wxml +4 -4
- package/miniprogram/ui-canvas/index.wxss +5 -5
- package/package/Buffer/index.ts +2 -2
- package/package/Canvas/index.ts +2 -2
- package/package/Cardinal/index.ts +2 -2
- package/package/Eoap/index.ts +2 -2
- package/package/Hermite/index.ts +2 -2
- package/package/Matrix4/index.ts +2 -2
- package/package/Mercator/index.ts +2 -2
- package/package/SVG/index.ts +2 -2
- package/package/Shader/index.ts +2 -39
- package/package/Texture/index.ts +2 -2
- package/package/TreeLayout/index.ts +2 -2
- package/package/animation/index.ts +2 -2
- package/package/getLoopColors/index.ts +2 -2
- package/package/index.ts +65 -76
- package/package/move/index.ts +2 -2
- package/package/rotate/index.ts +2 -2
- package/package/ruler/index.ts +2 -2
- package/package/scale/index.ts +2 -2
- package/package/throttle/index.ts +2 -2
- package/package.json +1 -1
- package/src/Eoap.ts +66 -66
- package/src/Matrix4/index.ts +84 -84
- package/src/Matrix4/move.ts +12 -12
- package/src/Matrix4/rotate.ts +15 -15
- package/src/Matrix4/scale.ts +11 -11
- package/src/Matrix4/transform.ts +64 -64
- package/src/Mercator.ts +27 -27
- package/src/SVG.ts +24 -24
- package/src/animation.ts +98 -98
- package/src/common/assemble.ts +22 -22
- package/src/common/canvas/arc.ts +51 -51
- package/src/common/canvas/config.ts +158 -158
- package/src/common/canvas/gradient.ts +24 -29
- package/src/common/canvas/index.ts +1 -12
- package/src/common/canvas/texts.ts +18 -18
- package/src/common/mergeOption.ts +6 -6
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +190 -190
- package/src/common/svg/gradient.ts +53 -63
- package/src/common/svg/index.ts +347 -356
- package/src/common/svg/tool.ts +44 -44
- package/src/common/tree/index.ts +25 -25
- 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/getWebGLContext.ts +1 -1
- package/src/common/webgl/shader.ts +75 -75
- package/src/common/webgl/texture.ts +97 -97
- package/src/getLoopColors.ts +42 -42
- package/src/interpolation/Cardinal.ts +110 -110
- package/src/interpolation/Hermite.ts +65 -65
- package/src/layout/TreeLayout.ts +188 -188
- package/src/move.ts +7 -7
- package/src/rotate.ts +7 -7
- package/src/ruler.ts +209 -209
- package/src/scale.ts +6 -6
- package/src/throttle.ts +52 -52
- package/types/Buffer.d.ts +23 -23
- package/types/CanvasConfig.d.ts +106 -106
- package/types/CanvasOption.d.ts +8 -8
- package/types/CanvasOpts.d.ts +9 -9
- package/types/Cardinal.d.ts +13 -13
- package/types/Gradient.d.ts +14 -14
- package/types/Hermite.d.ts +18 -18
- package/types/Map.d.ts +9 -9
- package/types/Matrix4.d.ts +47 -47
- package/types/SVG.d.ts +238 -238
- package/types/SVGConfig.d.ts +79 -79
- package/types/Shader.d.ts +16 -23
- package/types/Texture.d.ts +16 -16
- package/types/Tree.d.ts +69 -69
- package/types/TreeConfig.d.ts +36 -36
- package/types/TreeLayout.d.ts +54 -54
- package/types/TreeOption.d.ts +48 -48
- package/types/animation.d.ts +9 -6
- package/types/getLoopColors.d.ts +5 -2
- package/types/getWebGLContext.d.ts +3 -0
- package/types/index.d.ts +146 -176
- package/types/move.d.ts +5 -2
- package/types/painterConfig.d.ts +2 -2
- package/types/rotate.d.ts +5 -2
- package/types/ruler.d.ts +10 -7
- package/types/scale.d.ts +5 -2
- package/types/throttle.d.ts +7 -4
- package/types/throttleOption.d.ts +21 -21
- package/uni-app/ui-canvas.vue +4 -11
- package/lib/Geometry/index.umd.d.ts +0 -3
- package/lib/Geometry/index.umd.js +0 -353
- package/lib/Geometry/index.umd.min.d.ts +0 -3
- package/lib/Geometry/index.umd.min.js +0 -11
- package/lib/OralCanvas/index.es.d.ts +0 -3
- package/lib/OralCanvas/index.es.js +0 -693
- package/lib/OralCanvas/index.es.min.d.ts +0 -3
- package/lib/OralCanvas/index.es.min.js +0 -11
- package/lib/OralWebGL/index.es.d.ts +0 -3
- package/lib/OralWebGL/index.es.js +0 -639
- package/lib/OralWebGL/index.es.min.d.ts +0 -3
- package/lib/OralWebGL/index.es.min.js +0 -11
- package/lib/WebGL/index.umd.d.ts +0 -3
- package/lib/WebGL/index.umd.js +0 -712
- package/lib/WebGL/index.umd.min.d.ts +0 -3
- package/lib/WebGL/index.umd.min.js +0 -11
- package/lib/formatColor/index.umd.d.ts +0 -3
- package/lib/formatColor/index.umd.js +0 -59
- package/lib/formatColor/index.umd.min.d.ts +0 -3
- package/lib/formatColor/index.umd.min.js +0 -11
- package/lib/resizeObserver/index.umd.d.ts +0 -3
- package/lib/resizeObserver/index.umd.js +0 -49
- package/lib/resizeObserver/index.umd.min.d.ts +0 -3
- package/lib/resizeObserver/index.umd.min.js +0 -11
- package/lib/viewHandler/index.umd.d.ts +0 -3
- package/lib/viewHandler/index.umd.js +0 -139
- package/lib/viewHandler/index.umd.min.d.ts +0 -3
- package/lib/viewHandler/index.umd.min.js +0 -11
- package/package/Geometry/index.ts +0 -3
- package/package/OralCanvas/index.ts +0 -3
- package/package/OralWebGL/index.ts +0 -3
- package/package/WebGL/index.ts +0 -3
- package/package/formatColor/index.ts +0 -3
- package/package/resizeObserver/index.ts +0 -3
- package/package/viewHandler/index.ts +0 -3
- package/src/Geometry.ts +0 -211
- package/src/WebGL.ts +0 -67
- package/src/common/geometry/prism-horizontal.ts +0 -50
- package/src/common/geometry/prism-vertical.ts +0 -55
- package/src/common/geometry/sphere-fragment.ts +0 -40
- package/src/common/geometry/tool/circle.ts +0 -18
- package/src/common/geometry/tool/rotateLine.ts +0 -49
- package/src/common/geometry/tool/triangles.ts +0 -24
- package/src/common/webgl/doDraw.ts +0 -109
- package/src/common/webgl/getColorFactory.ts +0 -27
- package/src/common/webgl/getShader.ts +0 -49
- package/src/common/webgl/getTexture.ts +0 -12
- package/src/common/webgl/index.ts +0 -228
- package/src/formatColor.ts +0 -45
- package/src/resizeObserver.ts +0 -38
- package/src/shader/fsColor.c +0 -8
- package/src/shader/fsColors.c +0 -8
- package/src/shader/fsCube.c +0 -9
- package/src/shader/fsImage.c +0 -9
- package/src/shader/vsColor.c +0 -18
- package/src/shader/vsColors.c +0 -14
- package/src/shader/vsCube.c +0 -14
- package/src/shader/vsImage.c +0 -14
- package/src/viewHandler.ts +0 -161
- package/types/Geometry.d.ts +0 -133
- package/types/GeometryOption.d.ts +0 -12
- package/types/GeometryResult.d.ts +0 -19
- package/types/Object3D.d.ts +0 -115
- package/types/Scene3D.d.ts +0 -7
- package/types/WebGL.d.ts +0 -39
- package/types/WebGLOption.d.ts +0 -15
- package/types/formatColor.d.ts +0 -3
- package/types/resizeObserver.d.ts +0 -3
- package/types/viewHandler.d.ts +0 -14
|
@@ -1,228 +0,0 @@
|
|
|
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
|
-
export default WebGL
|
package/src/formatColor.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const toHex = (value: number) => {
|
|
2
|
-
const hex = value.toString(16)
|
|
3
|
-
return hex.length == 1 ? ("0" + hex) : hex
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export default function (color: string, format: string) {
|
|
7
|
-
|
|
8
|
-
const colorNode = document.getElementsByTagName('head')[0]
|
|
9
|
-
colorNode.style['color'] = color
|
|
10
|
-
|
|
11
|
-
// 获取结点的全部样式
|
|
12
|
-
const allStyle = document.defaultView && document.defaultView.getComputedStyle ?
|
|
13
|
-
document.defaultView.getComputedStyle(colorNode, null) :
|
|
14
|
-
(colorNode as any).currentStyle
|
|
15
|
-
|
|
16
|
-
const oralFormat = allStyle.getPropertyValue('color').replace(/rgba?\(/, '').replace(")", "").split(',')
|
|
17
|
-
for (let index = 0; index < oralFormat.length; index++) {
|
|
18
|
-
oralFormat[index] = +oralFormat[index]
|
|
19
|
-
}
|
|
20
|
-
oralFormat.push(1)
|
|
21
|
-
|
|
22
|
-
switch (format) {
|
|
23
|
-
case "3d": {
|
|
24
|
-
return [
|
|
25
|
-
oralFormat[0] / 255,
|
|
26
|
-
oralFormat[1] / 255,
|
|
27
|
-
oralFormat[2] / 255,
|
|
28
|
-
oralFormat[3]
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
case "rgba": {
|
|
32
|
-
return `rgba(${oralFormat[0]}, ${oralFormat[1]}, ${oralFormat[2]}, ${oralFormat[3]})`
|
|
33
|
-
}
|
|
34
|
-
case "rgb": {
|
|
35
|
-
return `rgb(${oralFormat[0]}, ${oralFormat[1]}, ${oralFormat[2]})`
|
|
36
|
-
}
|
|
37
|
-
case "hexAlpha": {
|
|
38
|
-
return `#${toHex(oralFormat[0])}${toHex(oralFormat[1])}${toHex(oralFormat[2])}${toHex(+(oralFormat[3] * 255).toFixed(0))}`
|
|
39
|
-
}
|
|
40
|
-
case "hex": {
|
|
41
|
-
return `#${toHex(oralFormat[0])}${toHex(oralFormat[1])}${toHex(oralFormat[2])}`
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
throw new Error("Unsupported color format: " + format)
|
|
45
|
-
}
|
package/src/resizeObserver.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
let observer: ResizeObserver
|
|
2
|
-
|
|
3
|
-
const attrValueToCallback = {}
|
|
4
|
-
let uniqueid = 0
|
|
5
|
-
|
|
6
|
-
export default function (el: HTMLElement | null, callback: Function) {
|
|
7
|
-
|
|
8
|
-
try {
|
|
9
|
-
|
|
10
|
-
if (!observer) {
|
|
11
|
-
observer = new ResizeObserver(entries => {
|
|
12
|
-
for (const entry of entries) {
|
|
13
|
-
attrValueToCallback[(entry.target as any)._resize_observer_]()
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
uniqueid++
|
|
19
|
-
|
|
20
|
-
(el as any)._resize_observer_ = uniqueid
|
|
21
|
-
attrValueToCallback[uniqueid] = callback
|
|
22
|
-
|
|
23
|
-
observer.observe(el as HTMLElement)
|
|
24
|
-
|
|
25
|
-
return function () {
|
|
26
|
-
if (observer) {
|
|
27
|
-
observer.unobserve(el as HTMLElement)
|
|
28
|
-
delete attrValueToCallback[(el as any)._resize_observer_]
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
} catch (e) {
|
|
33
|
-
callback()
|
|
34
|
-
|
|
35
|
-
// 如果浏览器不支持此接口
|
|
36
|
-
console.error('ResizeObserver undefined!')
|
|
37
|
-
}
|
|
38
|
-
}
|
package/src/shader/fsColor.c
DELETED
package/src/shader/fsColors.c
DELETED
package/src/shader/fsCube.c
DELETED
package/src/shader/fsImage.c
DELETED
package/src/shader/vsColor.c
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
attribute vec4 a_position;
|
|
2
|
-
uniform mat4 u_matrix;
|
|
3
|
-
|
|
4
|
-
void main()
|
|
5
|
-
{
|
|
6
|
-
vec4 temp = u_matrix * a_position;
|
|
7
|
-
|
|
8
|
-
// 把原生的WebGL使用的左手坐标系变成了右手坐标系
|
|
9
|
-
temp.z = -1.0 * temp.z;
|
|
10
|
-
|
|
11
|
-
// 表示眼睛距离vec4(0.0,0.0,1.0)的距离
|
|
12
|
-
float dist = 4.0;
|
|
13
|
-
|
|
14
|
-
// 使用投影直接计算
|
|
15
|
-
// 为保证纹理和相对位置正确
|
|
16
|
-
// x、y、z的改变满足线性变换
|
|
17
|
-
gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));
|
|
18
|
-
}
|
package/src/shader/vsColors.c
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
attribute vec4 a_position;
|
|
2
|
-
uniform mat4 u_matrix;
|
|
3
|
-
attribute vec4 a_color;
|
|
4
|
-
varying vec4 v_color;
|
|
5
|
-
|
|
6
|
-
void main()
|
|
7
|
-
{
|
|
8
|
-
vec4 temp = u_matrix * a_position;
|
|
9
|
-
temp.z = -1.0 * temp.z;
|
|
10
|
-
float dist = 4.0;
|
|
11
|
-
gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));
|
|
12
|
-
|
|
13
|
-
v_color = a_color;
|
|
14
|
-
}
|
package/src/shader/vsCube.c
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
attribute vec4 a_position;
|
|
2
|
-
uniform mat4 u_matrix;
|
|
3
|
-
attribute vec4 a_normal;
|
|
4
|
-
varying vec3 v_normal;
|
|
5
|
-
|
|
6
|
-
void main()
|
|
7
|
-
{
|
|
8
|
-
vec4 temp = u_matrix * a_position;
|
|
9
|
-
temp.z = -1.0 * temp.z;
|
|
10
|
-
float dist = 4.0;
|
|
11
|
-
gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));
|
|
12
|
-
|
|
13
|
-
v_normal = normalize(vec3(a_normal));
|
|
14
|
-
}
|
package/src/shader/vsImage.c
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
attribute vec4 a_position;
|
|
2
|
-
uniform mat4 u_matrix;
|
|
3
|
-
attribute vec2 a_textcoord;
|
|
4
|
-
varying vec2 v_textcoord;
|
|
5
|
-
|
|
6
|
-
void main()
|
|
7
|
-
{
|
|
8
|
-
vec4 temp = u_matrix * a_position;
|
|
9
|
-
temp.z = -1.0 * temp.z;
|
|
10
|
-
float dist = 4.0;
|
|
11
|
-
gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));
|
|
12
|
-
|
|
13
|
-
v_textcoord = a_textcoord;
|
|
14
|
-
}
|
package/src/viewHandler.ts
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import type { callbackFun } from '../types/viewHandler'
|
|
2
|
-
|
|
3
|
-
const mousePosition = (el: HTMLElement, event: any) => {
|
|
4
|
-
const bounding = el.getBoundingClientRect()
|
|
5
|
-
return {
|
|
6
|
-
"x": event.clientX - bounding.left,
|
|
7
|
-
"y": event.clientY - bounding.top
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const getKeyString = (event: any) => {
|
|
12
|
-
return {
|
|
13
|
-
37: "left",
|
|
14
|
-
38: "up",
|
|
15
|
-
39: "right",
|
|
16
|
-
40: "down",
|
|
17
|
-
}[event.keyCode || event.which]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default function (callback: callbackFun) {
|
|
21
|
-
|
|
22
|
-
const el = document.getElementsByTagName('body')[0]
|
|
23
|
-
|
|
24
|
-
// 键盘控制
|
|
25
|
-
el.addEventListener("keydown", function (event) {
|
|
26
|
-
const keyCode = getKeyString(event)
|
|
27
|
-
|
|
28
|
-
// 视角向上
|
|
29
|
-
if (keyCode == 'up') {
|
|
30
|
-
callback({
|
|
31
|
-
type: "lookUp",
|
|
32
|
-
normal: [],
|
|
33
|
-
value: 0.1,
|
|
34
|
-
event
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 视角向下
|
|
39
|
-
else if (keyCode == 'down') {
|
|
40
|
-
callback({
|
|
41
|
-
type: "lookDown",
|
|
42
|
-
normal: [],
|
|
43
|
-
value: 0.1,
|
|
44
|
-
event
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// 视角向左
|
|
49
|
-
else if (keyCode == 'left') {
|
|
50
|
-
callback({
|
|
51
|
-
type: "lookLeft",
|
|
52
|
-
normal: [],
|
|
53
|
-
value: 0.1,
|
|
54
|
-
event
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// 视角向右
|
|
59
|
-
else if (keyCode == 'right') {
|
|
60
|
-
callback({
|
|
61
|
-
type: "lookRight",
|
|
62
|
-
normal: [],
|
|
63
|
-
value: 0.1,
|
|
64
|
-
event
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
// 鼠标控制
|
|
71
|
-
let mouseP: {
|
|
72
|
-
[key: string]: number
|
|
73
|
-
} | null = null;
|
|
74
|
-
const doMove = function (event: any) {
|
|
75
|
-
|
|
76
|
-
// 单纯移动
|
|
77
|
-
if (mouseP == null) {
|
|
78
|
-
callback({
|
|
79
|
-
type: "hover",
|
|
80
|
-
normal: [],
|
|
81
|
-
value: 0,
|
|
82
|
-
event
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// 按下移动
|
|
87
|
-
else {
|
|
88
|
-
|
|
89
|
-
const tempMouseP = mousePosition(el, event)
|
|
90
|
-
|
|
91
|
-
// 先求解出轨迹向量
|
|
92
|
-
const normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y]
|
|
93
|
-
|
|
94
|
-
// 方向向量旋转90deg得到旋转向量
|
|
95
|
-
const rotateNormal = [
|
|
96
|
-
normal[1],
|
|
97
|
-
normal[0],
|
|
98
|
-
0
|
|
99
|
-
]
|
|
100
|
-
|
|
101
|
-
// 非法射线忽略
|
|
102
|
-
if (rotateNormal[0] == 0 && rotateNormal[1] == 0) return
|
|
103
|
-
|
|
104
|
-
callback({
|
|
105
|
-
type: "rotate",
|
|
106
|
-
normal: rotateNormal,
|
|
107
|
-
value: (Math.abs(tempMouseP.x - mouseP.x) + Math.abs(tempMouseP.y - mouseP.y)) * 0.01,
|
|
108
|
-
event
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
mouseP = tempMouseP
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
el.addEventListener("mousedown", (event) => {
|
|
116
|
-
mouseP = mousePosition(el, event)
|
|
117
|
-
})
|
|
118
|
-
el.addEventListener("mouseup", () => {
|
|
119
|
-
mouseP = null
|
|
120
|
-
})
|
|
121
|
-
el.addEventListener("mousemove", (event) => {
|
|
122
|
-
doMove(event)
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
// 手指控制
|
|
126
|
-
el.addEventListener("touchend", () => {
|
|
127
|
-
mouseP = null;
|
|
128
|
-
})
|
|
129
|
-
el.addEventListener("touchstart", (event) => {
|
|
130
|
-
mouseP = mousePosition(el, event)
|
|
131
|
-
})
|
|
132
|
-
el.addEventListener("touchmove", (event) => {
|
|
133
|
-
doMove(event.touches[0])
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
const doScale = function (value: number, event: Event) {
|
|
137
|
-
if (value == 0) return
|
|
138
|
-
|
|
139
|
-
const baseTimes = 0.899
|
|
140
|
-
callback({
|
|
141
|
-
type: "scale",
|
|
142
|
-
value: value < 0 ? baseTimes : 2 - baseTimes,
|
|
143
|
-
normal: [],
|
|
144
|
-
event
|
|
145
|
-
})
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// 滚轮控制
|
|
149
|
-
el.addEventListener("mousewheel", function (event: any) {
|
|
150
|
-
doScale(event.wheelDelta, event)
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
if (window.addEventListener) {
|
|
154
|
-
|
|
155
|
-
// 针对火狐浏览器
|
|
156
|
-
window.addEventListener('DOMMouseScroll', function (event: any) {
|
|
157
|
-
doScale(-1 * event.detail, event)
|
|
158
|
-
}, false)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
}
|