vislite 0.1.0 → 0.2.0-alpha.7
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 +24 -1
- package/LICENSE +20 -20
- package/README.md +53 -38
- package/lib/Canvas/index.umd.js +135 -46
- package/lib/Canvas/index.umd.min.js +7 -3
- package/lib/Cardinal/index.umd.js +6 -2
- package/lib/Cardinal/index.umd.min.js +6 -2
- package/lib/Eoap/index.umd.js +9 -5
- package/lib/Eoap/index.umd.min.js +6 -2
- package/lib/Hermite/index.umd.js +6 -2
- package/lib/Hermite/index.umd.min.js +6 -2
- package/lib/Matrix4/index.umd.js +6 -2
- package/lib/Matrix4/index.umd.min.js +6 -2
- package/lib/Mercator/index.umd.js +42 -0
- package/lib/Mercator/index.umd.min.js +15 -0
- package/lib/OralCanvas/index.es.js +124 -44
- package/lib/OralCanvas/index.es.min.js +7 -3
- package/lib/OralWebGL/index.es.js +567 -0
- package/lib/OralWebGL/index.es.min.js +15 -0
- package/lib/SVG/index.umd.js +16 -5
- package/lib/SVG/index.umd.min.js +7 -3
- package/lib/WebGL/index.umd.js +626 -0
- package/lib/WebGL/index.umd.min.js +15 -0
- package/lib/animation/index.umd.js +6 -2
- package/lib/animation/index.umd.min.js +6 -2
- package/lib/getLoopColors/index.umd.js +6 -2
- package/lib/getLoopColors/index.umd.min.js +6 -2
- package/lib/index.umd.js +1514 -863
- package/lib/index.umd.min.js +7 -3
- package/lib/rotate/index.umd.js +6 -2
- package/lib/rotate/index.umd.min.js +6 -2
- package/lib/ruler/index.umd.js +6 -2
- package/lib/ruler/index.umd.min.js +6 -2
- package/lib/viewHandler/index.umd.js +129 -0
- package/lib/viewHandler/index.umd.min.js +15 -0
- package/miniprogram/ui-canvas/index.js +18 -3
- 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/Canvas/index.ts +1 -1
- 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 +3 -0
- package/package/OralCanvas/index.ts +1 -1
- package/package/OralWebGL/index.ts +2 -0
- package/package/SVG/index.ts +2 -2
- package/package/WebGL/index.ts +2 -0
- package/package/animation/index.ts +2 -2
- package/package/getLoopColors/index.ts +2 -2
- package/package/index.ts +32 -9
- package/package/rotate/index.ts +2 -2
- package/package/ruler/index.ts +2 -2
- package/package/viewHandler/index.ts +3 -0
- package/package.json +11 -2
- package/src/Canvas.ts +10 -1
- package/src/Eoap.ts +5 -5
- package/src/Matrix4/index.ts +76 -76
- 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 -0
- package/src/SVG.ts +1 -1
- package/src/WebGL.ts +53 -0
- package/src/animation.ts +99 -99
- package/src/common/assemble.ts +23 -0
- package/src/common/canvas/arc.ts +50 -50
- package/src/common/canvas/config.ts +7 -6
- package/src/common/canvas/index.ts +29 -28
- package/src/common/canvas/painter.ts +51 -8
- package/src/common/canvas/texts.ts +19 -0
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +127 -126
- package/src/common/svg/index.ts +13 -3
- package/src/common/svg/tool.ts +43 -42
- package/src/common/webgl/buffer.ts +80 -0
- package/src/common/webgl/doDraw.ts +97 -0
- package/src/common/webgl/getColorFactory.ts +27 -0
- package/src/common/webgl/getShader.ts +62 -0
- package/src/common/webgl/getTexture.ts +12 -0
- package/src/common/webgl/getWebGLContext.ts +28 -0
- package/src/common/webgl/index.ts +212 -0
- package/src/common/webgl/shader.ts +76 -0
- package/src/common/webgl/texture.ts +99 -0
- package/src/getLoopColors.ts +42 -42
- package/src/interpolation/Cardinal.ts +91 -91
- package/src/interpolation/Hermite.ts +65 -65
- package/src/rotate.ts +7 -7
- package/src/ruler.ts +99 -99
- package/src/viewHandler.ts +140 -0
- package/types/Canvas.d.ts +220 -283
- package/types/CanvasConfig.d.ts +81 -0
- package/types/Cardinal.d.ts +13 -13
- package/types/Hermite.d.ts +18 -18
- package/types/Map.d.ts +10 -0
- package/types/Matrix4.d.ts +42 -42
- package/types/Object3D.d.ts +106 -0
- package/types/SVG.d.ts +210 -264
- package/types/SVGConfig.d.ts +59 -0
- package/types/Scene3D.d.ts +7 -0
- package/types/WebGL.d.ts +29 -0
- package/types/animation.d.ts +6 -6
- package/types/getLoopColors.d.ts +2 -2
- package/types/index.d.ts +70 -26
- package/types/rotate.d.ts +2 -2
- package/types/ruler.d.ts +2 -2
- package/types/viewHandler.d.ts +13 -0
- package/uni-app/ui-canvas.vue +94 -20
- package/types/Eoap.d.ts +0 -10
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import TextureObject from './texture'
|
|
2
|
+
|
|
3
|
+
let textures = {}
|
|
4
|
+
export default function (type: string, painter: WebGLRenderingContext, kind: string) {
|
|
5
|
+
let uniqueName = type + "-" + kind
|
|
6
|
+
|
|
7
|
+
if (!textures[uniqueName]) {
|
|
8
|
+
textures[uniqueName] = new TextureObject(painter, kind)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return textures[uniqueName]
|
|
12
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface OptsType {
|
|
2
|
+
preserveDrawingBuffer?: boolean
|
|
3
|
+
}
|
|
4
|
+
export default function (canvas: HTMLCanvasElement, scale: number, opts: OptsType = {}) {
|
|
5
|
+
let names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"], painter = null
|
|
6
|
+
for (let i = 0; i < names.length; i++) {
|
|
7
|
+
try {
|
|
8
|
+
painter = canvas.getContext(names[i], opts)
|
|
9
|
+
} catch (e) { }
|
|
10
|
+
if (painter) break
|
|
11
|
+
}
|
|
12
|
+
if (!painter) throw new Error('Non canvas or browser does not support webgl.')
|
|
13
|
+
|
|
14
|
+
let width = painter.canvas.width, height = painter.canvas.height
|
|
15
|
+
|
|
16
|
+
let viewWidth = width * scale
|
|
17
|
+
let viewHeight = height * scale
|
|
18
|
+
|
|
19
|
+
painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight)
|
|
20
|
+
|
|
21
|
+
// https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext/depthFunc
|
|
22
|
+
painter.depthFunc(painter.LEQUAL)
|
|
23
|
+
|
|
24
|
+
// 开启深度计算
|
|
25
|
+
painter.enable(painter.DEPTH_TEST);
|
|
26
|
+
|
|
27
|
+
return painter
|
|
28
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import getWebGLContext from './getWebGLContext'
|
|
2
|
+
import Object3DType from '../../../types/Object3D'
|
|
3
|
+
import Scene3DType from '../../../types/Scene3D'
|
|
4
|
+
import getColorFactory from './getColorFactory'
|
|
5
|
+
import Matrix4 from '../../Matrix4/index'
|
|
6
|
+
import doDraw from './doDraw'
|
|
7
|
+
import assemble from '../assemble'
|
|
8
|
+
|
|
9
|
+
// 获取区域信息前是否需要刷新区域
|
|
10
|
+
let needUpdate = false
|
|
11
|
+
|
|
12
|
+
let scale = 10
|
|
13
|
+
class WebGL {
|
|
14
|
+
|
|
15
|
+
readonly name: string = "WebGL"
|
|
16
|
+
|
|
17
|
+
painter: WebGLRenderingContext
|
|
18
|
+
private __regionPainter: WebGLRenderingContext
|
|
19
|
+
|
|
20
|
+
private __getColor = (x: number, y: number) => "rgba(0,0,0,1)"
|
|
21
|
+
|
|
22
|
+
private __regionList = {} //区域映射表
|
|
23
|
+
private __regionAssemble = assemble(0, 1, 0.2, 3)
|
|
24
|
+
|
|
25
|
+
private __regionName = "" // 当前绘制的内容名称
|
|
26
|
+
private __regionColor = [0, 0, 0, 1] // 当前记录区域应该使用的颜色
|
|
27
|
+
|
|
28
|
+
private __scene: Scene3DType = { // 记录着3D世界
|
|
29
|
+
children: [],
|
|
30
|
+
|
|
31
|
+
// 右手坐标系
|
|
32
|
+
matrix: new Matrix4([
|
|
33
|
+
1, 0, 0, 0,
|
|
34
|
+
0, 1, 0, 0,
|
|
35
|
+
0, 0, -1, 0,
|
|
36
|
+
0, 0, 0, scale
|
|
37
|
+
])
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private __proporion: number[]
|
|
41
|
+
|
|
42
|
+
private __unique: number
|
|
43
|
+
|
|
44
|
+
constructor(ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement) {
|
|
45
|
+
this.__unique = new Date().valueOf()
|
|
46
|
+
|
|
47
|
+
this.painter = getWebGLContext(ViewCanvas, scale)
|
|
48
|
+
this.__regionPainter = getWebGLContext(RegionCanvas, scale, {
|
|
49
|
+
|
|
50
|
+
// 如果不设置,涉及到缓冲区的情况可能无法获取颜色
|
|
51
|
+
// preserveDrawingBuffer: true
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
let proportion = this.painter.canvas.width / this.painter.canvas.height
|
|
55
|
+
|
|
56
|
+
let xProportion = 1
|
|
57
|
+
let yProportion = 1
|
|
58
|
+
|
|
59
|
+
if (proportion > 1) {
|
|
60
|
+
xProportion = 1 / proportion
|
|
61
|
+
} else {
|
|
62
|
+
yProportion = proportion
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let zProportion = Math.min(xProportion, yProportion)
|
|
66
|
+
|
|
67
|
+
this.__proporion = [
|
|
68
|
+
xProportion, 0, 0, 0,
|
|
69
|
+
0, yProportion, 0, 0,
|
|
70
|
+
0, 0, zProportion, 0,
|
|
71
|
+
0, 0, 0, 1
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
matrix(initMatrix4?: number[]) {
|
|
77
|
+
return new Matrix4(initMatrix4)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
getMatrix() {
|
|
81
|
+
return this.__scene.matrix
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
getObject3D() {
|
|
85
|
+
return this.__scene.children
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
review(isUpdateRegion = false) {
|
|
89
|
+
|
|
90
|
+
if (isUpdateRegion) {
|
|
91
|
+
this.__regionPainter.clearColor(1, 1, 1, 1)
|
|
92
|
+
this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT)
|
|
93
|
+
} else {
|
|
94
|
+
this.painter.clearColor(1, 1, 1, 1)
|
|
95
|
+
this.painter.clear(this.painter.COLOR_BUFFER_BIT)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
for (let index = 0; index < this.__scene.children.length; index++) {
|
|
99
|
+
this.draw(this.__scene.children[index], isUpdateRegion)
|
|
100
|
+
}
|
|
101
|
+
return this
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private draw(object3D: Object3DType, isUpdateRegion = false) {
|
|
105
|
+
if (!isUpdateRegion) needUpdate = true
|
|
106
|
+
|
|
107
|
+
let meshWorld = {
|
|
108
|
+
matrix: object3D.matrix.value()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let globalWorld = {
|
|
112
|
+
matrix: this.__scene.matrix.value(),
|
|
113
|
+
proporion: this.__proporion
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 设置好当前区域
|
|
117
|
+
this.setRegion(object3D.region)
|
|
118
|
+
|
|
119
|
+
for (let index = 0; index < object3D.mesh.length; index++) {
|
|
120
|
+
|
|
121
|
+
if (isUpdateRegion) {
|
|
122
|
+
// 区域上
|
|
123
|
+
doDraw("painter" + this.__unique, this.__regionPainter, {
|
|
124
|
+
geometry: object3D.mesh[index].geometry,
|
|
125
|
+
material: {
|
|
126
|
+
color: {
|
|
127
|
+
r: this.__regionColor[0],
|
|
128
|
+
g: this.__regionColor[1],
|
|
129
|
+
b: this.__regionColor[2],
|
|
130
|
+
alpha: this.__regionColor[3]
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}, meshWorld, globalWorld)
|
|
134
|
+
} else {
|
|
135
|
+
// 画布上
|
|
136
|
+
doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
this.__getColor = getColorFactory(this.__regionPainter)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
render(object3D: Object3DType) {
|
|
144
|
+
if (!('matrix' in object3D)) object3D.matrix = new Matrix4()
|
|
145
|
+
if (!('region' in object3D)) object3D.region = ""
|
|
146
|
+
|
|
147
|
+
// 对数据进行校对
|
|
148
|
+
for (let index = 0; index < object3D.mesh.length; index++) {
|
|
149
|
+
let mesh = object3D.mesh[index]
|
|
150
|
+
|
|
151
|
+
if (mesh.geometry.attributes.normal && Array.isArray(mesh.geometry.attributes.normal.array)) {
|
|
152
|
+
mesh.geometry.attributes.normal.array = new Float32Array(mesh.geometry.attributes.normal.array)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (mesh.geometry.attributes.position && Array.isArray(mesh.geometry.attributes.position.array)) {
|
|
156
|
+
mesh.geometry.attributes.position.array = new Float32Array(mesh.geometry.attributes.position.array)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (mesh.geometry.attributes.uv && Array.isArray(mesh.geometry.attributes.uv.array)) {
|
|
160
|
+
mesh.geometry.attributes.uv.array = new Float32Array(mesh.geometry.attributes.uv.array)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (mesh.geometry.index && Array.isArray(mesh.geometry.index.array)) {
|
|
164
|
+
mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
this.__scene.children.push(object3D)
|
|
170
|
+
this.draw(object3D)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// 设置当前绘制区域名称
|
|
174
|
+
setRegion(regionName: string | number) {
|
|
175
|
+
this.__regionName = regionName + ""
|
|
176
|
+
|
|
177
|
+
if (regionName) {
|
|
178
|
+
if (this.__regionList[regionName] == undefined) {
|
|
179
|
+
this.__regionList[regionName] = [... this.__regionAssemble(), 1]
|
|
180
|
+
}
|
|
181
|
+
this.__regionColor = this.__regionList[regionName]
|
|
182
|
+
} else {
|
|
183
|
+
this.__regionColor = [0, 0, 0, 1]
|
|
184
|
+
}
|
|
185
|
+
return this
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// 获取当前事件触发的区域名称
|
|
189
|
+
getRegion(x: number, y: number): Promise<string> {
|
|
190
|
+
if (needUpdate) this.review(true)
|
|
191
|
+
|
|
192
|
+
needUpdate = false
|
|
193
|
+
return new Promise((resolve, reject) => {
|
|
194
|
+
|
|
195
|
+
let rgba = this.__getColor(x, y)
|
|
196
|
+
|
|
197
|
+
// 查找当前点击的区域
|
|
198
|
+
for (let key in this.__regionList) {
|
|
199
|
+
let currentRGBA = this.__regionList[key]
|
|
200
|
+
if ("rgba(" + currentRGBA[0] * 255 + "," + currentRGBA[1] * 255 + "," + currentRGBA[2] * 255 + "," + currentRGBA[3] * 255 + ")" == rgba) {
|
|
201
|
+
resolve(key)
|
|
202
|
+
break
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
resolve("")
|
|
206
|
+
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export default WebGL
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// 着色器分为两类:顶点着色器 + 片段着色器
|
|
2
|
+
// 前者用于定义一个点的特性,比如位置,大小,颜色等
|
|
3
|
+
// 后者用于针对每个片段(可以理解为像素)进行处理
|
|
4
|
+
|
|
5
|
+
// 着色器采用的语言是:GLSL ES语言
|
|
6
|
+
|
|
7
|
+
// 把着色器字符串加载成着色器对象
|
|
8
|
+
let loadShader = (painter: WebGLRenderingContext, type: number, source: string) => {
|
|
9
|
+
|
|
10
|
+
// 创建着色器对象
|
|
11
|
+
let shader = painter.createShader(type)
|
|
12
|
+
if (shader == null) throw new Error('Unable to create shader!')
|
|
13
|
+
|
|
14
|
+
// 绑定资源
|
|
15
|
+
painter.shaderSource(shader, source)
|
|
16
|
+
|
|
17
|
+
// 编译着色器
|
|
18
|
+
painter.compileShader(shader)
|
|
19
|
+
|
|
20
|
+
// 检测着色器编译是否成功
|
|
21
|
+
if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
|
|
22
|
+
throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader))
|
|
23
|
+
|
|
24
|
+
return shader
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 建立着色器
|
|
28
|
+
let useShader = (painter: WebGLRenderingContext, vshaderSource: string, fshaderSource: string) => {
|
|
29
|
+
|
|
30
|
+
// 分别加载顶点着色器对象和片段着色器对象
|
|
31
|
+
let vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource)
|
|
32
|
+
let fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource)
|
|
33
|
+
|
|
34
|
+
// 创建一个着色器程序
|
|
35
|
+
let glProgram = painter.createProgram()
|
|
36
|
+
|
|
37
|
+
// 把前面创建的两个着色器对象添加到着色器程序中
|
|
38
|
+
painter.attachShader(glProgram, vertexShader)
|
|
39
|
+
painter.attachShader(glProgram, fragmentShader)
|
|
40
|
+
|
|
41
|
+
// 把着色器程序链接成一个完整的程序
|
|
42
|
+
painter.linkProgram(glProgram)
|
|
43
|
+
|
|
44
|
+
// 检测着色器程序链接是否成功
|
|
45
|
+
if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
|
|
46
|
+
throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram))
|
|
47
|
+
|
|
48
|
+
return glProgram
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
class ShaderObject {
|
|
52
|
+
|
|
53
|
+
private __painter: WebGLRenderingContext
|
|
54
|
+
|
|
55
|
+
program: WebGLProgram
|
|
56
|
+
|
|
57
|
+
constructor(painter: WebGLRenderingContext) {
|
|
58
|
+
this.__painter = painter
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 使用这个程序
|
|
62
|
+
// (后于编译)
|
|
63
|
+
use() {
|
|
64
|
+
this.__painter.useProgram(this.program)
|
|
65
|
+
return this
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 编译着色器程序
|
|
69
|
+
compile(vshaderSource: string, fshaderSource: string) {
|
|
70
|
+
this.program = useShader(this.__painter, vshaderSource, fshaderSource)
|
|
71
|
+
return this
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default ShaderObject
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// 初始化一个纹理对象
|
|
2
|
+
// type = gl.TEXTURE_2D 二维纹理
|
|
3
|
+
// type = gl.TEXTURE_CUBE_MAP 立方体纹理
|
|
4
|
+
// unit表示开启的纹理单元编号
|
|
5
|
+
let initTexture = (painter: WebGLRenderingContext, type: number, unit: number) => {
|
|
6
|
+
|
|
7
|
+
// 创建纹理对象
|
|
8
|
+
let texture = painter.createTexture()
|
|
9
|
+
|
|
10
|
+
if (type == painter.TEXTURE_2D) {
|
|
11
|
+
|
|
12
|
+
// 开启纹理单元,unit表示开启的编号
|
|
13
|
+
painter.activeTexture(painter['TEXTURE' + unit])
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 绑定纹理对象到目标上
|
|
17
|
+
painter.bindTexture(type, texture)
|
|
18
|
+
|
|
19
|
+
return texture
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 链接资源图片
|
|
23
|
+
// level默认传入0即可,和金字塔纹理有关
|
|
24
|
+
// format表示图像的内部格式:
|
|
25
|
+
// gl.RGB(红绿蓝)
|
|
26
|
+
// gl.RGBA(红绿蓝透明度)
|
|
27
|
+
// gl.ALPHA(0.0,0.0,0.0,透明度)
|
|
28
|
+
// gl.LUMINANCE(L、L、L、1L:流明)
|
|
29
|
+
// gl.LUMINANCE_ALPHA(L、L、L,透明度)
|
|
30
|
+
// textureType表示纹理数据的格式:
|
|
31
|
+
// gl.UNSIGNED_BYTE: 表示无符号整形,每一个颜色分量占据1字节
|
|
32
|
+
// gl.UNSIGNED_SHORT_5_6_5: 表示RGB,每一个分量分别占据占据5, 6, 5比特
|
|
33
|
+
// gl.UNSIGNED_SHORT_4_4_4_4: 表示RGBA,每一个分量分别占据占据4, 4, 4, 4比特
|
|
34
|
+
// gl.UNSIGNED_SHORT_5_5_5_1: 表示RGBA,每一个分量分别占据占据5比特,A分量占据1比特
|
|
35
|
+
let linkImage = (painter: WebGLRenderingContext, type: number, level: number, format: number, textureType: number, image: TexImageSource) => {
|
|
36
|
+
painter.texImage2D(type, level, format, format, textureType, image)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let linkCube = (painter: WebGLRenderingContext, type: number, level: number, format: number, textureType: number, images: TexImageSource[], width: number, height: number, texture: WebGLTexture) => {
|
|
40
|
+
|
|
41
|
+
let types = [
|
|
42
|
+
painter.TEXTURE_CUBE_MAP_POSITIVE_X, // 右
|
|
43
|
+
painter.TEXTURE_CUBE_MAP_NEGATIVE_X, // 左
|
|
44
|
+
painter.TEXTURE_CUBE_MAP_POSITIVE_Y, // 上
|
|
45
|
+
painter.TEXTURE_CUBE_MAP_NEGATIVE_Y, // 下
|
|
46
|
+
painter.TEXTURE_CUBE_MAP_POSITIVE_Z, // 后
|
|
47
|
+
painter.TEXTURE_CUBE_MAP_NEGATIVE_Z // 前
|
|
48
|
+
], target: number
|
|
49
|
+
|
|
50
|
+
for (let i = 0; i < types.length; i++) {
|
|
51
|
+
if (images[i]) {
|
|
52
|
+
target = types[i]
|
|
53
|
+
painter.texImage2D(target, level, format, width, height, 0, format, textureType, null)
|
|
54
|
+
painter.bindTexture(type, texture)
|
|
55
|
+
painter.texImage2D(target, level, format, format, textureType, images[i])
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
painter.generateMipmap(type)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
class TextureObject {
|
|
63
|
+
|
|
64
|
+
private __painter: WebGLRenderingContext
|
|
65
|
+
private __type: number
|
|
66
|
+
|
|
67
|
+
private __texture: WebGLTexture
|
|
68
|
+
|
|
69
|
+
constructor(painter: WebGLRenderingContext, type: string, unit = 0) {
|
|
70
|
+
this.__painter = painter
|
|
71
|
+
this.__type = {
|
|
72
|
+
"2d": painter.TEXTURE_2D,
|
|
73
|
+
"cube": painter.TEXTURE_CUBE_MAP
|
|
74
|
+
}[type]
|
|
75
|
+
|
|
76
|
+
// 创建纹理
|
|
77
|
+
this.__texture = initTexture(painter, this.__type, unit)
|
|
78
|
+
|
|
79
|
+
// 配置纹理
|
|
80
|
+
painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST)
|
|
81
|
+
painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE)
|
|
82
|
+
painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 链接图片资源(单一)
|
|
86
|
+
useImage(image: TexImageSource) {
|
|
87
|
+
linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image)
|
|
88
|
+
return this
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 链接图片资源(多张)
|
|
92
|
+
useCube(images: TexImageSource[], width: number, height: number) {
|
|
93
|
+
linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture)
|
|
94
|
+
return this
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export default TextureObject
|
package/src/getLoopColors.ts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
// 获取一组循环色彩
|
|
2
|
-
export default function (num: number, alpha: number = 1) {
|
|
3
|
-
// 颜色集合
|
|
4
|
-
let colorList = [
|
|
5
|
-
'rgba(84,112,198,' + alpha + ")", 'rgba(145,204,117,' + alpha + ")",
|
|
6
|
-
'rgba(250,200,88,' + alpha + ")", 'rgba(238,102,102,' + alpha + ")",
|
|
7
|
-
'rgba(115,192,222,' + alpha + ")", 'rgba(59,162,114,' + alpha + ")",
|
|
8
|
-
'rgba(252,132,82,' + alpha + ")", 'rgba(154,96,180,' + alpha + ")",
|
|
9
|
-
'rgba(234,124,204,' + alpha + ")"
|
|
10
|
-
]
|
|
11
|
-
|
|
12
|
-
let colors: string[] = []
|
|
13
|
-
|
|
14
|
-
// 根据情况返回颜色数组
|
|
15
|
-
if (num <= colorList.length) {
|
|
16
|
-
// 这种情况就不需要任何处理
|
|
17
|
-
return colorList
|
|
18
|
-
} else {
|
|
19
|
-
// 如果正好是集合长度的倍数
|
|
20
|
-
if (num % colorList.length == 0) {
|
|
21
|
-
// 将颜色数组循环加入后再返回
|
|
22
|
-
for (let i = 0; i < (num / colorList.length); i++) {
|
|
23
|
-
colors = colors.concat(colorList)
|
|
24
|
-
}
|
|
25
|
-
} else {
|
|
26
|
-
for (let j = 1; j < (num / colorList.length); j++) {
|
|
27
|
-
colors = colors.concat(colorList)
|
|
28
|
-
}
|
|
29
|
-
// 防止最后一个颜色和第一个颜色重复
|
|
30
|
-
if (num % colorList.length == 1) {
|
|
31
|
-
colors = colors.concat(colorList[4])
|
|
32
|
-
} else {
|
|
33
|
-
for (let k = 0; k < num % colorList.length; k++) {
|
|
34
|
-
colors = colors.concat(colorList[k])
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 返回结果
|
|
41
|
-
return colors
|
|
42
|
-
}
|
|
1
|
+
// 获取一组循环色彩
|
|
2
|
+
export default function (num: number, alpha: number = 1) {
|
|
3
|
+
// 颜色集合
|
|
4
|
+
let colorList = [
|
|
5
|
+
'rgba(84,112,198,' + alpha + ")", 'rgba(145,204,117,' + alpha + ")",
|
|
6
|
+
'rgba(250,200,88,' + alpha + ")", 'rgba(238,102,102,' + alpha + ")",
|
|
7
|
+
'rgba(115,192,222,' + alpha + ")", 'rgba(59,162,114,' + alpha + ")",
|
|
8
|
+
'rgba(252,132,82,' + alpha + ")", 'rgba(154,96,180,' + alpha + ")",
|
|
9
|
+
'rgba(234,124,204,' + alpha + ")"
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
let colors: string[] = []
|
|
13
|
+
|
|
14
|
+
// 根据情况返回颜色数组
|
|
15
|
+
if (num <= colorList.length) {
|
|
16
|
+
// 这种情况就不需要任何处理
|
|
17
|
+
return colorList
|
|
18
|
+
} else {
|
|
19
|
+
// 如果正好是集合长度的倍数
|
|
20
|
+
if (num % colorList.length == 0) {
|
|
21
|
+
// 将颜色数组循环加入后再返回
|
|
22
|
+
for (let i = 0; i < (num / colorList.length); i++) {
|
|
23
|
+
colors = colors.concat(colorList)
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
for (let j = 1; j < (num / colorList.length); j++) {
|
|
27
|
+
colors = colors.concat(colorList)
|
|
28
|
+
}
|
|
29
|
+
// 防止最后一个颜色和第一个颜色重复
|
|
30
|
+
if (num % colorList.length == 1) {
|
|
31
|
+
colors = colors.concat(colorList[4])
|
|
32
|
+
} else {
|
|
33
|
+
for (let k = 0; k < num % colorList.length; k++) {
|
|
34
|
+
colors = colors.concat(colorList[k])
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 返回结果
|
|
41
|
+
return colors
|
|
42
|
+
}
|