vislite 0.3.0-alpha.0 → 0.3.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 +18 -5
- package/lib/Buffer/index.umd.js +55 -0
- package/lib/Buffer/index.umd.min.js +11 -0
- package/lib/Canvas/index.umd.js +2 -6
- package/lib/Canvas/index.umd.min.js +2 -6
- package/lib/Cardinal/index.umd.js +16 -9
- package/lib/Cardinal/index.umd.min.js +3 -7
- package/lib/Eoap/index.umd.js +2 -6
- package/lib/Eoap/index.umd.min.js +2 -6
- package/lib/Hermite/index.umd.js +2 -6
- package/lib/Hermite/index.umd.min.js +2 -6
- package/lib/Matrix4/index.umd.js +2 -6
- package/lib/Matrix4/index.umd.min.js +2 -6
- package/lib/Mercator/index.umd.js +2 -6
- package/lib/Mercator/index.umd.min.js +2 -6
- package/lib/OralCanvas/index.es.js +2 -6
- package/lib/OralCanvas/index.es.min.js +2 -6
- package/lib/OralWebGL/index.es.js +15 -10
- package/lib/OralWebGL/index.es.min.js +3 -7
- package/lib/SVG/index.umd.js +2 -6
- package/lib/SVG/index.umd.min.js +2 -6
- package/lib/Shader/index.umd.js +55 -0
- package/lib/Shader/index.umd.min.js +11 -0
- package/lib/Texture/index.umd.js +74 -0
- package/lib/Texture/index.umd.min.js +11 -0
- package/lib/WebGL/index.umd.js +15 -10
- package/lib/WebGL/index.umd.min.js +3 -7
- package/lib/animation/index.umd.js +2 -6
- package/lib/animation/index.umd.min.js +2 -6
- package/lib/getLoopColors/index.umd.js +2 -6
- package/lib/getLoopColors/index.umd.min.js +2 -6
- package/lib/getWebGLContext/index.umd.js +65 -0
- package/lib/getWebGLContext/index.umd.min.js +11 -0
- package/lib/index.umd.js +60 -16
- package/lib/index.umd.min.js +3 -7
- package/lib/rotate/index.umd.js +2 -6
- package/lib/rotate/index.umd.min.js +2 -6
- package/lib/ruler/index.umd.js +2 -6
- package/lib/ruler/index.umd.min.js +2 -6
- package/lib/viewHandler/index.umd.js +2 -6
- package/lib/viewHandler/index.umd.min.js +2 -6
- package/package/Buffer/index.ts +2 -0
- package/package/Shader/index.ts +2 -0
- package/package/Texture/index.ts +2 -0
- package/package/getWebGLContext/index.ts +40 -0
- package/package/index.ts +11 -0
- package/package.json +2 -2
- package/src/common/webgl/doDraw.ts +13 -3
- package/src/common/webgl/getShader.ts +7 -1
- package/src/common/webgl/index.ts +4 -0
- package/src/interpolation/Cardinal.ts +22 -4
- package/types/Buffer.d.ts +24 -0
- package/types/Object3D.d.ts +7 -0
- package/types/Shader.d.ts +16 -0
- package/types/Texture.d.ts +17 -0
- package/types/getWebGLContext.d.ts +3 -0
- package/types/index.d.ts +28 -0
|
@@ -20,7 +20,7 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
20
20
|
// 点数据写入缓冲区
|
|
21
21
|
new BufferObject(painter).use()
|
|
22
22
|
.write(mesh.geometry.attributes.position.array as Float32Array)
|
|
23
|
-
.divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize,
|
|
23
|
+
.divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, mesh.geometry.attributes.position.itemSize, 0)
|
|
24
24
|
|
|
25
25
|
// 写入矩阵
|
|
26
26
|
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix)
|
|
@@ -31,7 +31,7 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
31
31
|
if (mesh.geometry.attributes.normal) {
|
|
32
32
|
new BufferObject(painter).use()
|
|
33
33
|
.write(mesh.geometry.attributes.normal.array as Float32Array)
|
|
34
|
-
.divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize,
|
|
34
|
+
.divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, mesh.geometry.attributes.normal.itemSize, 0)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// 颜色
|
|
@@ -45,10 +45,20 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
45
45
|
, mesh.material.color.alpha)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
// 多颜色
|
|
49
|
+
if ("colors" in mesh.material) {
|
|
50
|
+
|
|
51
|
+
// 写入颜色序列
|
|
52
|
+
new BufferObject(painter).use()
|
|
53
|
+
.write(mesh.material.colors.array as Float32Array)
|
|
54
|
+
.divide(painter.getAttribLocation(shader.program, "a_color"), mesh.material.colors.itemSize, mesh.material.colors.itemSize, 0)
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
48
58
|
// 立方纹理
|
|
49
59
|
else if ("cube" in mesh.material) {
|
|
50
60
|
|
|
51
|
-
let size = mesh.material.cube.right.image.value.width
|
|
61
|
+
let size = (mesh.material.cube.right.image.value as any).width
|
|
52
62
|
|
|
53
63
|
getTexture(type, painter, 'cube').useCube([
|
|
54
64
|
mesh.material.cube.right.image.value,
|
|
@@ -9,12 +9,13 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
9
9
|
(mesh.geometry.attributes.normal ? "1" : "0") +
|
|
10
10
|
(mesh.material.image ? "1" : "0") +
|
|
11
11
|
(mesh.material.color ? "1" : "0") +
|
|
12
|
+
(mesh.material.colors ? "1" : "0") +
|
|
12
13
|
(mesh.material.cube ? "1" : "0")
|
|
13
14
|
if (shaders[uniqueName]) return shaders[uniqueName].use()
|
|
14
15
|
|
|
15
16
|
// 顶点着色器
|
|
16
17
|
let vertexShader = `
|
|
17
|
-
|
|
18
|
+
attribute vec4 a_position;
|
|
18
19
|
|
|
19
20
|
${mesh.geometry.attributes.normal ? 'attribute vec4 a_normal;varying vec3 v_normal;' : ''}
|
|
20
21
|
|
|
@@ -24,6 +25,8 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
24
25
|
|
|
25
26
|
${mesh.material.image ? 'attribute vec2 a_textcoord;varying vec2 v_textcoord;' : ''}
|
|
26
27
|
|
|
28
|
+
${mesh.material.colors ? 'attribute vec4 a_color;varying vec4 v_color;' : ''}
|
|
29
|
+
|
|
27
30
|
void main(){
|
|
28
31
|
vec4 temp = a_position;
|
|
29
32
|
|
|
@@ -43,6 +46,7 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
43
46
|
|
|
44
47
|
${mesh.geometry.attributes.normal ? 'v_normal = normalize(vec3(a_normal));' : ''}
|
|
45
48
|
${mesh.material.image ? 'v_textcoord = a_textcoord;' : ''}
|
|
49
|
+
${mesh.material.colors ? 'v_color=a_color;' : ''}
|
|
46
50
|
}
|
|
47
51
|
`
|
|
48
52
|
|
|
@@ -54,11 +58,13 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
|
|
|
54
58
|
${mesh.material.color ? 'uniform vec4 u_color;' : ''}
|
|
55
59
|
${mesh.material.cube ? 'uniform samplerCube u_texture;' : ''}
|
|
56
60
|
${mesh.material.image ? 'uniform sampler2D u_sampler;varying vec2 v_textcoord;' : ''}
|
|
61
|
+
${mesh.material.colors ? 'varying vec4 v_color;' : ''}
|
|
57
62
|
|
|
58
63
|
void main(){
|
|
59
64
|
${mesh.material.color ? 'gl_FragColor = u_color;' : ''}
|
|
60
65
|
${mesh.material.cube ? 'gl_FragColor = textureCube(u_texture,normalize(v_normal));' : ''}
|
|
61
66
|
${mesh.material.image ? 'gl_FragColor = texture2D(u_sampler,v_textcoord);' : ''}
|
|
67
|
+
${mesh.material.colors ? 'gl_FragColor=v_color;' : ''}
|
|
62
68
|
}
|
|
63
69
|
`
|
|
64
70
|
|
|
@@ -165,6 +165,10 @@ class WebGL {
|
|
|
165
165
|
mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array)
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
if (mesh.material.colors && Array.isArray(mesh.material.colors.array)) {
|
|
169
|
+
mesh.material.colors.array = new Float32Array(mesh.material.colors.array)
|
|
170
|
+
}
|
|
171
|
+
|
|
168
172
|
}
|
|
169
173
|
|
|
170
174
|
this.__scene.children.push(object3D)
|
|
@@ -46,11 +46,29 @@ class Cardinal implements CardinalType {
|
|
|
46
46
|
this.__HS.x[flag] = points[flag][0]
|
|
47
47
|
|
|
48
48
|
// 求点斜率
|
|
49
|
-
temp = flag < points.length - 1 ?
|
|
50
|
-
(points[flag + 1][1] - points[flag - 1][1]) / (points[flag + 1][0] - points[flag - 1][0]) :
|
|
51
|
-
(points[flag][1] - points[flag - 1][1]) / (points[flag][0] - points[flag - 1][0])
|
|
52
49
|
|
|
53
|
-
//
|
|
50
|
+
// temp = flag < points.length - 1 ?
|
|
51
|
+
// (points[flag + 1][1] - points[flag - 1][1]) / (points[flag + 1][0] - points[flag - 1][0]) :
|
|
52
|
+
// (points[flag][1] - points[flag - 1][1]) / (points[flag][0] - points[flag - 1][0])
|
|
53
|
+
|
|
54
|
+
// 修复超过界限的值问题
|
|
55
|
+
// 2023年6月25日 于南京
|
|
56
|
+
if (flag < points.length - 1) {
|
|
57
|
+
if (
|
|
58
|
+
(points[flag + 1][1] > points[flag][1] && points[flag - 1][1] > points[flag][1]) ||
|
|
59
|
+
(points[flag + 1][1] < points[flag][1] && points[flag - 1][1] < points[flag][1]) ||
|
|
60
|
+
points[flag + 1][1] == points[flag][1] ||
|
|
61
|
+
points[flag - 1][1] == points[flag][1]
|
|
62
|
+
) {
|
|
63
|
+
temp = 0
|
|
64
|
+
} else {
|
|
65
|
+
temp = (points[flag + 1][1] - points[flag - 1][1]) / (points[flag + 1][0] - points[flag - 1][0])
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
temp = (points[flag][1] - points[flag - 1][1]) / (points[flag][0] - points[flag - 1][0])
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 求解两个点直接的插值方程
|
|
54
72
|
// 第一个点的前一个点直接取第一个点
|
|
55
73
|
// 最后一个点的后一个点直接取最后一个点
|
|
56
74
|
this.__HS.h[flag - 1] = new Hermite((1 - this.__t) * 0.5).setP(points[flag - 1][0], points[flag - 1][1], points[flag][0], points[flag][1], slope, temp)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export default interface BufferType {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 使用这个缓冲区对象
|
|
5
|
+
* (先于写入和分配)
|
|
6
|
+
*/
|
|
7
|
+
use(): this
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 写入数据
|
|
11
|
+
* @param data 具体的数据内容
|
|
12
|
+
*/
|
|
13
|
+
write(data: Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array): this
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 分配使用
|
|
17
|
+
* @param location 变量位置
|
|
18
|
+
* @param size 一个数据的长度
|
|
19
|
+
* @param stride 一组数据的长度(可能包含多组)
|
|
20
|
+
* @param offset 读取位置偏移
|
|
21
|
+
*/
|
|
22
|
+
divide(location: number, size: number, stride: number, offset?: number): this
|
|
23
|
+
|
|
24
|
+
}
|
package/types/Object3D.d.ts
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default interface ShaderType {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 使用这个程序
|
|
5
|
+
* (后于编译)
|
|
6
|
+
*/
|
|
7
|
+
use(): this
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 编译着色器程序
|
|
11
|
+
* @param vshaderSource 顶点着色器
|
|
12
|
+
* @param fshaderSource 片段(元)着色器
|
|
13
|
+
*/
|
|
14
|
+
compile(vshaderSource: string, fshaderSource: string): this
|
|
15
|
+
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default interface TextureType {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 链接图片资源(单一)
|
|
5
|
+
* @param image 纹理图片
|
|
6
|
+
*/
|
|
7
|
+
useImage(image: TexImageSource): this
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 链接图片资源(多张)
|
|
11
|
+
* @param images 纹理图片集
|
|
12
|
+
* @param width 图片宽
|
|
13
|
+
* @param height 图片高
|
|
14
|
+
*/
|
|
15
|
+
useCube(images: TexImageSource[], width: number, height: number): this
|
|
16
|
+
|
|
17
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -12,6 +12,11 @@ import SVGType from './SVG'
|
|
|
12
12
|
import CanvasType from './Canvas'
|
|
13
13
|
import WebGLType from './WebGL'
|
|
14
14
|
|
|
15
|
+
import getWebGLContextType from './getWebGLContext'
|
|
16
|
+
import ShaderType from './Shader'
|
|
17
|
+
import BufferType from './Buffer'
|
|
18
|
+
import TextureType from './Texture'
|
|
19
|
+
|
|
15
20
|
import MapType from './Map'
|
|
16
21
|
|
|
17
22
|
import viewHandlerType from './viewHandler'
|
|
@@ -40,6 +45,17 @@ interface NewWebGLType extends WebGLType {
|
|
|
40
45
|
new(el: HTMLElement | null): this
|
|
41
46
|
}
|
|
42
47
|
|
|
48
|
+
// WebGL
|
|
49
|
+
interface NewShaderType extends ShaderType {
|
|
50
|
+
new(painter: WebGLRenderingContext): this
|
|
51
|
+
}
|
|
52
|
+
interface NewBufferType extends BufferType {
|
|
53
|
+
new(painter: WebGLRenderingContext, isElement?: boolean): this
|
|
54
|
+
}
|
|
55
|
+
interface NewTextureType extends TextureType {
|
|
56
|
+
new(painter: WebGLRenderingContext, type: string, unit?: number): this
|
|
57
|
+
}
|
|
58
|
+
|
|
43
59
|
// 投影
|
|
44
60
|
interface NewEoapType extends MapType {
|
|
45
61
|
new(scale?: number, center?: number[]): this
|
|
@@ -68,6 +84,12 @@ export default class VISLite {
|
|
|
68
84
|
static Canvas: NewCanvasType
|
|
69
85
|
static WebGL: NewWebGLType
|
|
70
86
|
|
|
87
|
+
// WebGL
|
|
88
|
+
static getWebGLContext: getWebGLContextType
|
|
89
|
+
static Shader: NewShaderType
|
|
90
|
+
static Buffer: NewBufferType
|
|
91
|
+
static Texture: NewTextureType
|
|
92
|
+
|
|
71
93
|
// 投影
|
|
72
94
|
static Eoap: NewEoapType
|
|
73
95
|
static Mercator: NewMercatorType
|
|
@@ -94,6 +116,12 @@ export let SVG: NewSVGType
|
|
|
94
116
|
export let Canvas: NewCanvasType
|
|
95
117
|
export let WebGL: NewWebGLType
|
|
96
118
|
|
|
119
|
+
// WebGL
|
|
120
|
+
export let getWebGLContext: getWebGLContextType
|
|
121
|
+
export let Shader: NewShaderType
|
|
122
|
+
export let Buffer: NewBufferType
|
|
123
|
+
export let Texture: NewTextureType
|
|
124
|
+
|
|
97
125
|
// 投影
|
|
98
126
|
export let Eoap: NewEoapType
|
|
99
127
|
export let Mercator: NewMercatorType
|