vislite 0.5.2-alpha.1 → 0.5.2
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/.editorconfig +18 -18
- package/AUTHORS.txt +6 -6
- package/CHANGELOG +143 -137
- package/LICENSE +20 -20
- package/README.md +69 -69
- package/lib/Buffer/index.umd.js +36 -36
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +650 -650
- 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 +142 -142
- 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 +119 -119
- 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 +598 -598
- package/lib/OralCanvas/index.es.min.js +2 -2
- package/lib/OralWebGL/index.es.js +532 -532
- package/lib/OralWebGL/index.es.min.js +3 -3
- package/lib/SVG/index.umd.js +470 -405
- package/lib/SVG/index.umd.min.js +3 -3
- package/lib/Shader/index.umd.js +69 -69
- package/lib/Shader/index.umd.min.js +3 -3
- package/lib/Texture/index.umd.js +53 -53
- package/lib/Texture/index.umd.min.js +2 -2
- package/lib/TreeLayout/index.umd.js +363 -363
- package/lib/TreeLayout/index.umd.min.js +2 -2
- package/lib/WebGL/index.umd.js +579 -579
- package/lib/WebGL/index.umd.min.js +3 -3
- package/lib/animation/index.umd.js +72 -72
- 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 +44 -44
- package/lib/getWebGLContext/index.umd.min.js +2 -2
- package/lib/index.umd.js +2744 -2662
- package/lib/index.umd.min.js +3 -3
- package/lib/move/index.umd.js +27 -0
- package/lib/move/index.umd.min.js +11 -0
- package/lib/resizeObserver/index.umd.js +29 -29
- 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 +126 -126
- package/lib/ruler/index.umd.min.js +2 -2
- package/lib/scale/index.umd.js +26 -0
- package/lib/scale/index.umd.min.js +11 -0
- 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/index.js +107 -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/Geometry/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/OralCanvas/index.ts +2 -2
- package/package/OralWebGL/index.ts +2 -2
- package/package/SVG/index.ts +2 -2
- package/package/Shader/index.ts +39 -39
- package/package/Texture/index.ts +2 -2
- package/package/TreeLayout/index.ts +2 -2
- package/package/WebGL/index.ts +2 -2
- package/package/animation/index.ts +2 -2
- package/package/formatColor/index.ts +2 -2
- package/package/getLoopColors/index.ts +2 -2
- package/package/getWebGLContext/index.ts +39 -39
- package/package/index.ts +76 -72
- package/package/move/index.ts +3 -0
- package/package/resizeObserver/index.ts +2 -2
- package/package/rotate/index.ts +2 -2
- package/package/ruler/index.ts +2 -2
- package/package/scale/index.ts +3 -0
- package/package/throttle/index.ts +2 -2
- package/package/viewHandler/index.ts +2 -2
- package/package.json +66 -66
- package/src/Canvas.ts +67 -67
- package/src/Eoap.ts +66 -66
- package/src/Geometry.ts +82 -82
- 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 -27
- package/src/SVG.ts +24 -24
- package/src/TreeLayout/index.ts +186 -186
- package/src/WebGL.ts +66 -66
- package/src/animation.ts +98 -98
- package/src/common/assemble.ts +22 -22
- package/src/common/canvas/arc.ts +50 -50
- package/src/common/canvas/config.ts +158 -158
- package/src/common/canvas/gradient.ts +29 -29
- package/src/common/canvas/index.ts +168 -168
- package/src/common/canvas/painter.ts +426 -426
- package/src/common/canvas/texts.ts +18 -18
- package/src/common/geometry/prism-horizontal.ts +33 -33
- package/src/common/geometry/prism-vertical.ts +40 -40
- package/src/common/geometry/sphere-fragment.ts +39 -39
- package/src/common/geometry/tool/circle.ts +11 -11
- package/src/common/mergeOption.ts +6 -6
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +186 -174
- package/src/common/svg/gradient.ts +63 -0
- package/src/common/svg/index.ts +356 -344
- package/src/common/svg/tool.ts +44 -44
- package/src/common/tree/index.ts +25 -25
- package/src/common/tree/toInnerTree.ts +56 -56
- package/src/common/tree/toPlainTree.ts +131 -131
- package/src/common/webgl/buffer.ts +79 -79
- package/src/common/webgl/doDraw.ts +108 -108
- package/src/common/webgl/getColorFactory.ts +26 -26
- package/src/common/webgl/getShader.ts +48 -48
- package/src/common/webgl/getTexture.ts +11 -11
- package/src/common/webgl/getWebGLContext.ts +27 -27
- package/src/common/webgl/index.ts +223 -223
- package/src/common/webgl/shader.ts +75 -75
- package/src/common/webgl/texture.ts +96 -96
- package/src/formatColor.ts +44 -44
- package/src/getLoopColors.ts +42 -42
- package/src/interpolation/Cardinal.ts +110 -110
- package/src/interpolation/Hermite.ts +65 -65
- package/src/move.ts +8 -0
- package/src/resizeObserver.ts +36 -36
- package/src/rotate.ts +7 -7
- package/src/ruler.ts +188 -188
- package/src/scale.ts +7 -0
- package/src/shader/fsColor.c +7 -7
- package/src/shader/fsColors.c +7 -7
- package/src/shader/fsCube.c +8 -8
- package/src/shader/fsImage.c +8 -8
- package/src/shader/vsColor.c +17 -17
- package/src/shader/vsColors.c +13 -13
- package/src/shader/vsCube.c +13 -13
- package/src/shader/vsImage.c +13 -13
- package/src/throttle.ts +51 -51
- package/src/viewHandler.ts +158 -158
- package/types/Buffer.d.ts +23 -23
- package/types/Canvas.d.ts +300 -300
- package/types/CanvasConfig.d.ts +106 -106
- package/types/CanvasOption.d.ts +7 -7
- package/types/Cardinal.d.ts +13 -13
- package/types/Geometry.d.ts +40 -40
- package/types/GeometryOption.d.ts +11 -11
- package/types/GeometryResult.d.ts +18 -18
- 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 +42 -42
- package/types/Object3D.d.ts +114 -114
- package/types/SVG.d.ts +238 -215
- package/types/SVGConfig.d.ts +76 -76
- package/types/Scene3D.d.ts +6 -6
- package/types/Shader.d.ts +21 -21
- package/types/Texture.d.ts +16 -16
- package/types/Tree.d.ts +69 -69
- package/types/TreeConfig.d.ts +24 -24
- package/types/TreeLayout.d.ts +54 -54
- package/types/TreeOption.d.ts +48 -48
- package/types/WebGL.d.ts +38 -38
- package/types/WebGLOption.d.ts +7 -7
- package/types/animation.d.ts +6 -6
- package/types/formatColor.d.ts +2 -2
- package/types/getLoopColors.d.ts +2 -2
- package/types/getWebGLContext.d.ts +2 -2
- package/types/index.d.ts +175 -169
- package/types/move.d.ts +3 -0
- package/types/painterConfig.d.ts +2 -2
- package/types/resizeObserver.d.ts +2 -2
- package/types/rotate.d.ts +2 -2
- package/types/ruler.d.ts +7 -7
- package/types/scale.d.ts +3 -0
- package/types/throttle.d.ts +4 -4
- package/types/throttleOption.d.ts +21 -21
- package/types/viewHandler.d.ts +13 -13
- package/uni-app/ui-canvas.vue +226 -226
package/lib/WebGL/index.umd.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.5.2
|
|
2
|
+
* VISLite JavaScript Library v0.5.2
|
|
3
3
|
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
4
|
*
|
|
5
5
|
* Copyright zxl20070701
|
|
6
6
|
* Released under the MIT license
|
|
7
7
|
* https://zxl20070701.github.io/notebook/home.html
|
|
8
8
|
*
|
|
9
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sat Nov 04 2023 09:25:44 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
11
|
(function (global, factory) {
|
|
12
12
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -60,623 +60,623 @@
|
|
|
60
60
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
function getWebGLContext (canvas, scale, opts) {
|
|
64
|
-
if (opts === void 0) { opts = {}; }
|
|
65
|
-
var names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"], painter = null;
|
|
66
|
-
for (var i = 0; i < names.length; i++) {
|
|
67
|
-
try {
|
|
68
|
-
painter = canvas.getContext(names[i], opts);
|
|
69
|
-
}
|
|
70
|
-
catch (e) { }
|
|
71
|
-
if (painter)
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
if (!painter)
|
|
75
|
-
throw new Error('Non canvas or browser does not support webgl.');
|
|
76
|
-
var width = painter.canvas.width, height = painter.canvas.height;
|
|
77
|
-
var viewWidth = width * scale;
|
|
78
|
-
var viewHeight = height * scale;
|
|
79
|
-
painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight);
|
|
80
|
-
painter.depthFunc(painter.LEQUAL);
|
|
81
|
-
painter.enable(painter.DEPTH_TEST);
|
|
82
|
-
return painter;
|
|
63
|
+
function getWebGLContext (canvas, scale, opts) {
|
|
64
|
+
if (opts === void 0) { opts = {}; }
|
|
65
|
+
var names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"], painter = null;
|
|
66
|
+
for (var i = 0; i < names.length; i++) {
|
|
67
|
+
try {
|
|
68
|
+
painter = canvas.getContext(names[i], opts);
|
|
69
|
+
}
|
|
70
|
+
catch (e) { }
|
|
71
|
+
if (painter)
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
if (!painter)
|
|
75
|
+
throw new Error('Non canvas or browser does not support webgl.');
|
|
76
|
+
var width = painter.canvas.width, height = painter.canvas.height;
|
|
77
|
+
var viewWidth = width * scale;
|
|
78
|
+
var viewHeight = height * scale;
|
|
79
|
+
painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight);
|
|
80
|
+
painter.depthFunc(painter.LEQUAL);
|
|
81
|
+
painter.enable(painter.DEPTH_TEST);
|
|
82
|
+
return painter;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
function getColorFactory (painter) {
|
|
86
|
-
var width = painter.drawingBufferWidth, height = painter.drawingBufferHeight;
|
|
87
|
-
var pixels = new Uint8Array(4 * width * height);
|
|
88
|
-
painter.readPixels(0, 0, width, height, painter.RGBA, painter.UNSIGNED_BYTE, pixels);
|
|
89
|
-
return function (x, y) {
|
|
90
|
-
y = height - y;
|
|
91
|
-
var pixelR = pixels[4 * (y * width + x)];
|
|
92
|
-
var pixelG = pixels[4 * (y * width + x) + 1];
|
|
93
|
-
var pixelB = pixels[4 * (y * width + x) + 2];
|
|
94
|
-
var pixelA = pixels[4 * (y * width + x) + 3];
|
|
95
|
-
return "rgba(" + pixelR + "," + pixelG + "," + pixelB + "," + pixelA + ")";
|
|
96
|
-
};
|
|
85
|
+
function getColorFactory (painter) {
|
|
86
|
+
var width = painter.drawingBufferWidth, height = painter.drawingBufferHeight;
|
|
87
|
+
var pixels = new Uint8Array(4 * width * height);
|
|
88
|
+
painter.readPixels(0, 0, width, height, painter.RGBA, painter.UNSIGNED_BYTE, pixels);
|
|
89
|
+
return function (x, y) {
|
|
90
|
+
y = height - y;
|
|
91
|
+
var pixelR = pixels[4 * (y * width + x)];
|
|
92
|
+
var pixelG = pixels[4 * (y * width + x) + 1];
|
|
93
|
+
var pixelB = pixels[4 * (y * width + x) + 2];
|
|
94
|
+
var pixelA = pixels[4 * (y * width + x) + 3];
|
|
95
|
+
return "rgba(" + pixelR + "," + pixelG + "," + pixelB + "," + pixelA + ")";
|
|
96
|
+
};
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
function _move (d, a, b, c) {
|
|
100
|
-
if (c === void 0) { c = 0; }
|
|
101
|
-
var sqrt = Math.sqrt(a * a + b * b + c * c);
|
|
102
|
-
return [
|
|
103
|
-
1, 0, 0, 0,
|
|
104
|
-
0, 1, 0, 0,
|
|
105
|
-
0, 0, 1, 0,
|
|
106
|
-
a * d / sqrt, b * d / sqrt, c * d / sqrt, 1
|
|
107
|
-
];
|
|
99
|
+
function _move (d, a, b, c) {
|
|
100
|
+
if (c === void 0) { c = 0; }
|
|
101
|
+
var sqrt = Math.sqrt(a * a + b * b + c * c);
|
|
102
|
+
return [
|
|
103
|
+
1, 0, 0, 0,
|
|
104
|
+
0, 1, 0, 0,
|
|
105
|
+
0, 0, 1, 0,
|
|
106
|
+
a * d / sqrt, b * d / sqrt, c * d / sqrt, 1
|
|
107
|
+
];
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
function _rotate (deg) {
|
|
111
|
-
var sin = Math.sin(deg), cos = Math.cos(deg);
|
|
112
|
-
return [
|
|
113
|
-
cos, sin, 0, 0,
|
|
114
|
-
-sin, cos, 0, 0,
|
|
115
|
-
0, 0, 1, 0,
|
|
116
|
-
0, 0, 0, 1
|
|
117
|
-
];
|
|
110
|
+
function _rotate (deg) {
|
|
111
|
+
var sin = Math.sin(deg), cos = Math.cos(deg);
|
|
112
|
+
return [
|
|
113
|
+
cos, sin, 0, 0,
|
|
114
|
+
-sin, cos, 0, 0,
|
|
115
|
+
0, 0, 1, 0,
|
|
116
|
+
0, 0, 0, 1
|
|
117
|
+
];
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
function _scale (xTimes, yTimes, zTimes, cx, cy, cz) {
|
|
121
|
-
if (cx === void 0) { cx = 0; }
|
|
122
|
-
if (cy === void 0) { cy = 0; }
|
|
123
|
-
if (cz === void 0) { cz = 0; }
|
|
124
|
-
return [
|
|
125
|
-
xTimes, 0, 0, 0,
|
|
126
|
-
0, yTimes, 0, 0,
|
|
127
|
-
0, 0, zTimes, 0,
|
|
128
|
-
cx - cx * xTimes, cy - cy * yTimes, cz - cz * zTimes, 1
|
|
129
|
-
];
|
|
120
|
+
function _scale (xTimes, yTimes, zTimes, cx, cy, cz) {
|
|
121
|
+
if (cx === void 0) { cx = 0; }
|
|
122
|
+
if (cy === void 0) { cy = 0; }
|
|
123
|
+
if (cz === void 0) { cz = 0; }
|
|
124
|
+
return [
|
|
125
|
+
xTimes, 0, 0, 0,
|
|
126
|
+
0, yTimes, 0, 0,
|
|
127
|
+
0, 0, zTimes, 0,
|
|
128
|
+
cx - cx * xTimes, cy - cy * yTimes, cz - cz * zTimes, 1
|
|
129
|
+
];
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
function _transform (a1, b1, c1, a2, b2, c2) {
|
|
133
|
-
if (typeof a1 === 'number' && typeof b1 === 'number') {
|
|
134
|
-
if (typeof c1 !== 'number') {
|
|
135
|
-
c1 = 0;
|
|
136
|
-
a2 = a1;
|
|
137
|
-
b2 = b1;
|
|
138
|
-
c2 = 1;
|
|
139
|
-
}
|
|
140
|
-
else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
|
|
141
|
-
a2 = a1;
|
|
142
|
-
b2 = b1;
|
|
143
|
-
c2 = c1;
|
|
144
|
-
a1 = 0;
|
|
145
|
-
b1 = 0;
|
|
146
|
-
c1 = 0;
|
|
147
|
-
}
|
|
148
|
-
if (a1 == a2 && b1 == b2 && c1 == c2)
|
|
149
|
-
throw new Error('It\'s not a legitimate ray!');
|
|
150
|
-
var sqrt1 = Math.sqrt((a2 - a1) * (a2 - a1) + (b2 - b1) * (b2 - b1)), cos1 = sqrt1 != 0 ? (b2 - b1) / sqrt1 : 1, sin1 = sqrt1 != 0 ? (a2 - a1) / sqrt1 : 0, b = (a2 - a1) * sin1 + (b2 - b1) * cos1, c = c2 - c1, sqrt2 = Math.sqrt(b * b + c * c), cos2 = sqrt2 != 0 ? c / sqrt2 : 1, sin2 = sqrt2 != 0 ? b / sqrt2 : 0;
|
|
151
|
-
return [
|
|
152
|
-
[
|
|
153
|
-
cos1, cos2 * sin1, sin1 * sin2, 0,
|
|
154
|
-
-sin1, cos1 * cos2, cos1 * sin2, 0,
|
|
155
|
-
0, -sin2, cos2, 0,
|
|
156
|
-
b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
|
|
157
|
-
],
|
|
158
|
-
[
|
|
159
|
-
cos1, -sin1, 0, 0,
|
|
160
|
-
cos2 * sin1, cos2 * cos1, -sin2, 0,
|
|
161
|
-
sin1 * sin2, cos1 * sin2, cos2, 0,
|
|
162
|
-
a1, b1, c1, 1
|
|
163
|
-
]
|
|
164
|
-
];
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
throw new Error('a1 and b1 is required!');
|
|
168
|
-
}
|
|
132
|
+
function _transform (a1, b1, c1, a2, b2, c2) {
|
|
133
|
+
if (typeof a1 === 'number' && typeof b1 === 'number') {
|
|
134
|
+
if (typeof c1 !== 'number') {
|
|
135
|
+
c1 = 0;
|
|
136
|
+
a2 = a1;
|
|
137
|
+
b2 = b1;
|
|
138
|
+
c2 = 1;
|
|
139
|
+
}
|
|
140
|
+
else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
|
|
141
|
+
a2 = a1;
|
|
142
|
+
b2 = b1;
|
|
143
|
+
c2 = c1;
|
|
144
|
+
a1 = 0;
|
|
145
|
+
b1 = 0;
|
|
146
|
+
c1 = 0;
|
|
147
|
+
}
|
|
148
|
+
if (a1 == a2 && b1 == b2 && c1 == c2)
|
|
149
|
+
throw new Error('It\'s not a legitimate ray!');
|
|
150
|
+
var sqrt1 = Math.sqrt((a2 - a1) * (a2 - a1) + (b2 - b1) * (b2 - b1)), cos1 = sqrt1 != 0 ? (b2 - b1) / sqrt1 : 1, sin1 = sqrt1 != 0 ? (a2 - a1) / sqrt1 : 0, b = (a2 - a1) * sin1 + (b2 - b1) * cos1, c = c2 - c1, sqrt2 = Math.sqrt(b * b + c * c), cos2 = sqrt2 != 0 ? c / sqrt2 : 1, sin2 = sqrt2 != 0 ? b / sqrt2 : 0;
|
|
151
|
+
return [
|
|
152
|
+
[
|
|
153
|
+
cos1, cos2 * sin1, sin1 * sin2, 0,
|
|
154
|
+
-sin1, cos1 * cos2, cos1 * sin2, 0,
|
|
155
|
+
0, -sin2, cos2, 0,
|
|
156
|
+
b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
|
|
157
|
+
],
|
|
158
|
+
[
|
|
159
|
+
cos1, -sin1, 0, 0,
|
|
160
|
+
cos2 * sin1, cos2 * cos1, -sin2, 0,
|
|
161
|
+
sin1 * sin2, cos1 * sin2, cos2, 0,
|
|
162
|
+
a1, b1, c1, 1
|
|
163
|
+
]
|
|
164
|
+
];
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
throw new Error('a1 and b1 is required!');
|
|
168
|
+
}
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
var _multiply = function (matrix4, param) {
|
|
172
|
-
var newParam = [];
|
|
173
|
-
for (var i = 0; i < 4; i++)
|
|
174
|
-
for (var j = 0; j < param.length / 4; j++)
|
|
175
|
-
newParam[j * 4 + i] =
|
|
176
|
-
matrix4[i] * param[j * 4] +
|
|
177
|
-
matrix4[i + 4] * param[j * 4 + 1] +
|
|
178
|
-
matrix4[i + 8] * param[j * 4 + 2] +
|
|
179
|
-
matrix4[i + 12] * param[j * 4 + 3];
|
|
180
|
-
return newParam;
|
|
181
|
-
};
|
|
182
|
-
var Matrix4 = (function () {
|
|
183
|
-
function Matrix4(initMatrix4) {
|
|
184
|
-
if (initMatrix4 === void 0) { initMatrix4 = [
|
|
185
|
-
1, 0, 0, 0,
|
|
186
|
-
0, 1, 0, 0,
|
|
187
|
-
0, 0, 1, 0,
|
|
188
|
-
0, 0, 0, 1
|
|
189
|
-
]; }
|
|
190
|
-
this.name = 'Matrix4';
|
|
191
|
-
this.__matrix4 = initMatrix4;
|
|
192
|
-
}
|
|
193
|
-
Matrix4.prototype.move = function (dis, a, b, c) {
|
|
194
|
-
if (c === void 0) { c = 0; }
|
|
195
|
-
this.__matrix4 = _multiply(_move(dis, a, b, c), this.__matrix4);
|
|
196
|
-
return this;
|
|
197
|
-
};
|
|
198
|
-
Matrix4.prototype.rotate = function (deg, a1, b1, c1, a2, b2, c2) {
|
|
199
|
-
var matrix4s = _transform(a1, b1, c1, a2, b2, c2);
|
|
200
|
-
this.__matrix4 = _multiply(_multiply(_multiply(matrix4s[1], _rotate(deg)), matrix4s[0]), this.__matrix4);
|
|
201
|
-
return this;
|
|
202
|
-
};
|
|
203
|
-
Matrix4.prototype.scale = function (xTimes, yTimes, zTimes, cx, cy, cz) {
|
|
204
|
-
if (cx === void 0) { cx = 0; }
|
|
205
|
-
if (cy === void 0) { cy = 0; }
|
|
206
|
-
if (cz === void 0) { cz = 0; }
|
|
207
|
-
this.__matrix4 = _multiply(_scale(xTimes, yTimes, zTimes, cx, cy, cz), this.__matrix4);
|
|
208
|
-
return this;
|
|
209
|
-
};
|
|
210
|
-
Matrix4.prototype.multiply = function (newMatrix4, flag) {
|
|
211
|
-
if (flag === void 0) { flag = false; }
|
|
212
|
-
this.__matrix4 = flag ? _multiply(this.__matrix4, newMatrix4) : _multiply(newMatrix4, this.__matrix4);
|
|
213
|
-
return this;
|
|
214
|
-
};
|
|
215
|
-
Matrix4.prototype.use = function (x, y, z, w) {
|
|
216
|
-
if (z === void 0) { z = 0; }
|
|
217
|
-
if (w === void 0) { w = 1; }
|
|
218
|
-
return _multiply(this.__matrix4, [x, y, z, w]);
|
|
219
|
-
};
|
|
220
|
-
Matrix4.prototype.value = function () {
|
|
221
|
-
return this.__matrix4;
|
|
222
|
-
};
|
|
223
|
-
return Matrix4;
|
|
171
|
+
var _multiply = function (matrix4, param) {
|
|
172
|
+
var newParam = [];
|
|
173
|
+
for (var i = 0; i < 4; i++)
|
|
174
|
+
for (var j = 0; j < param.length / 4; j++)
|
|
175
|
+
newParam[j * 4 + i] =
|
|
176
|
+
matrix4[i] * param[j * 4] +
|
|
177
|
+
matrix4[i + 4] * param[j * 4 + 1] +
|
|
178
|
+
matrix4[i + 8] * param[j * 4 + 2] +
|
|
179
|
+
matrix4[i + 12] * param[j * 4 + 3];
|
|
180
|
+
return newParam;
|
|
181
|
+
};
|
|
182
|
+
var Matrix4 = (function () {
|
|
183
|
+
function Matrix4(initMatrix4) {
|
|
184
|
+
if (initMatrix4 === void 0) { initMatrix4 = [
|
|
185
|
+
1, 0, 0, 0,
|
|
186
|
+
0, 1, 0, 0,
|
|
187
|
+
0, 0, 1, 0,
|
|
188
|
+
0, 0, 0, 1
|
|
189
|
+
]; }
|
|
190
|
+
this.name = 'Matrix4';
|
|
191
|
+
this.__matrix4 = initMatrix4;
|
|
192
|
+
}
|
|
193
|
+
Matrix4.prototype.move = function (dis, a, b, c) {
|
|
194
|
+
if (c === void 0) { c = 0; }
|
|
195
|
+
this.__matrix4 = _multiply(_move(dis, a, b, c), this.__matrix4);
|
|
196
|
+
return this;
|
|
197
|
+
};
|
|
198
|
+
Matrix4.prototype.rotate = function (deg, a1, b1, c1, a2, b2, c2) {
|
|
199
|
+
var matrix4s = _transform(a1, b1, c1, a2, b2, c2);
|
|
200
|
+
this.__matrix4 = _multiply(_multiply(_multiply(matrix4s[1], _rotate(deg)), matrix4s[0]), this.__matrix4);
|
|
201
|
+
return this;
|
|
202
|
+
};
|
|
203
|
+
Matrix4.prototype.scale = function (xTimes, yTimes, zTimes, cx, cy, cz) {
|
|
204
|
+
if (cx === void 0) { cx = 0; }
|
|
205
|
+
if (cy === void 0) { cy = 0; }
|
|
206
|
+
if (cz === void 0) { cz = 0; }
|
|
207
|
+
this.__matrix4 = _multiply(_scale(xTimes, yTimes, zTimes, cx, cy, cz), this.__matrix4);
|
|
208
|
+
return this;
|
|
209
|
+
};
|
|
210
|
+
Matrix4.prototype.multiply = function (newMatrix4, flag) {
|
|
211
|
+
if (flag === void 0) { flag = false; }
|
|
212
|
+
this.__matrix4 = flag ? _multiply(this.__matrix4, newMatrix4) : _multiply(newMatrix4, this.__matrix4);
|
|
213
|
+
return this;
|
|
214
|
+
};
|
|
215
|
+
Matrix4.prototype.use = function (x, y, z, w) {
|
|
216
|
+
if (z === void 0) { z = 0; }
|
|
217
|
+
if (w === void 0) { w = 1; }
|
|
218
|
+
return _multiply(this.__matrix4, [x, y, z, w]);
|
|
219
|
+
};
|
|
220
|
+
Matrix4.prototype.value = function () {
|
|
221
|
+
return this.__matrix4;
|
|
222
|
+
};
|
|
223
|
+
return Matrix4;
|
|
224
224
|
}());
|
|
225
225
|
|
|
226
|
-
var newBuffer = function (painter) {
|
|
227
|
-
return painter.createBuffer();
|
|
228
|
-
};
|
|
229
|
-
var writeBuffer = function (painter, data, isElement, usage) {
|
|
230
|
-
var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
|
|
231
|
-
painter.bufferData(TYPE, data, usage);
|
|
232
|
-
};
|
|
233
|
-
var useBuffer = function (painter, location, size, type, stride, offset, normalized) {
|
|
234
|
-
painter.vertexAttribPointer(location, size, type, normalized, stride, offset);
|
|
235
|
-
painter.enableVertexAttribArray(location);
|
|
236
|
-
};
|
|
237
|
-
var BufferObject = (function () {
|
|
238
|
-
function BufferObject(painter, isElement) {
|
|
239
|
-
if (isElement === void 0) { isElement = false; }
|
|
240
|
-
this.__painter = painter;
|
|
241
|
-
this.__isElement = isElement;
|
|
242
|
-
this.__buffer = newBuffer(painter);
|
|
243
|
-
this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
|
|
244
|
-
}
|
|
245
|
-
BufferObject.prototype.use = function () {
|
|
246
|
-
this.__painter.bindBuffer(this.__type, this.__buffer);
|
|
247
|
-
return this;
|
|
248
|
-
};
|
|
249
|
-
BufferObject.prototype.write = function (data) {
|
|
250
|
-
writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW);
|
|
251
|
-
this.__fsize = data.BYTES_PER_ELEMENT;
|
|
252
|
-
return this;
|
|
253
|
-
};
|
|
254
|
-
BufferObject.prototype.divide = function (location, size, stride, offset) {
|
|
255
|
-
if (offset === void 0) { offset = 0; }
|
|
256
|
-
useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false);
|
|
257
|
-
return this;
|
|
258
|
-
};
|
|
259
|
-
return BufferObject;
|
|
226
|
+
var newBuffer = function (painter) {
|
|
227
|
+
return painter.createBuffer();
|
|
228
|
+
};
|
|
229
|
+
var writeBuffer = function (painter, data, isElement, usage) {
|
|
230
|
+
var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
|
|
231
|
+
painter.bufferData(TYPE, data, usage);
|
|
232
|
+
};
|
|
233
|
+
var useBuffer = function (painter, location, size, type, stride, offset, normalized) {
|
|
234
|
+
painter.vertexAttribPointer(location, size, type, normalized, stride, offset);
|
|
235
|
+
painter.enableVertexAttribArray(location);
|
|
236
|
+
};
|
|
237
|
+
var BufferObject = (function () {
|
|
238
|
+
function BufferObject(painter, isElement) {
|
|
239
|
+
if (isElement === void 0) { isElement = false; }
|
|
240
|
+
this.__painter = painter;
|
|
241
|
+
this.__isElement = isElement;
|
|
242
|
+
this.__buffer = newBuffer(painter);
|
|
243
|
+
this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
|
|
244
|
+
}
|
|
245
|
+
BufferObject.prototype.use = function () {
|
|
246
|
+
this.__painter.bindBuffer(this.__type, this.__buffer);
|
|
247
|
+
return this;
|
|
248
|
+
};
|
|
249
|
+
BufferObject.prototype.write = function (data) {
|
|
250
|
+
writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW);
|
|
251
|
+
this.__fsize = data.BYTES_PER_ELEMENT;
|
|
252
|
+
return this;
|
|
253
|
+
};
|
|
254
|
+
BufferObject.prototype.divide = function (location, size, stride, offset) {
|
|
255
|
+
if (offset === void 0) { offset = 0; }
|
|
256
|
+
useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false);
|
|
257
|
+
return this;
|
|
258
|
+
};
|
|
259
|
+
return BufferObject;
|
|
260
260
|
}());
|
|
261
261
|
|
|
262
|
-
var initTexture = function (painter, type, unit) {
|
|
263
|
-
var texture = painter.createTexture();
|
|
264
|
-
painter.activeTexture(painter['TEXTURE' + unit]);
|
|
265
|
-
painter.bindTexture(type, texture);
|
|
266
|
-
return texture;
|
|
267
|
-
};
|
|
268
|
-
var linkImage = function (painter, type, level, format, textureType, image) {
|
|
269
|
-
painter.texImage2D(type, level, format, format, textureType, image);
|
|
270
|
-
};
|
|
271
|
-
var linkCube = function (painter, type, level, format, textureType, images, width, height, texture) {
|
|
272
|
-
var types = [
|
|
273
|
-
painter.TEXTURE_CUBE_MAP_POSITIVE_X,
|
|
274
|
-
painter.TEXTURE_CUBE_MAP_NEGATIVE_X,
|
|
275
|
-
painter.TEXTURE_CUBE_MAP_POSITIVE_Y,
|
|
276
|
-
painter.TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
|
277
|
-
painter.TEXTURE_CUBE_MAP_POSITIVE_Z,
|
|
278
|
-
painter.TEXTURE_CUBE_MAP_NEGATIVE_Z
|
|
279
|
-
], target;
|
|
280
|
-
for (var i = 0; i < types.length; i++) {
|
|
281
|
-
if (images[i]) {
|
|
282
|
-
target = types[i];
|
|
283
|
-
painter.texImage2D(target, level, format, width, height, 0, format, textureType, null);
|
|
284
|
-
painter.bindTexture(type, texture);
|
|
285
|
-
painter.texImage2D(target, level, format, format, textureType, images[i]);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
painter.generateMipmap(type);
|
|
289
|
-
};
|
|
290
|
-
var TextureObject = (function () {
|
|
291
|
-
function TextureObject(painter, type, unit) {
|
|
292
|
-
if (unit === void 0) { unit = 0; }
|
|
293
|
-
this.__painter = painter;
|
|
294
|
-
this.__type = {
|
|
295
|
-
"2d": painter.TEXTURE_2D,
|
|
296
|
-
"cube": painter.TEXTURE_CUBE_MAP
|
|
297
|
-
}[type];
|
|
298
|
-
this.__texture = initTexture(painter, this.__type, unit);
|
|
299
|
-
painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
|
|
300
|
-
painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST);
|
|
301
|
-
painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
|
|
302
|
-
painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
|
|
303
|
-
}
|
|
304
|
-
TextureObject.prototype.useImage = function (image) {
|
|
305
|
-
linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image);
|
|
306
|
-
return this;
|
|
307
|
-
};
|
|
308
|
-
TextureObject.prototype.useCube = function (images, width, height) {
|
|
309
|
-
linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture);
|
|
310
|
-
return this;
|
|
311
|
-
};
|
|
312
|
-
return TextureObject;
|
|
262
|
+
var initTexture = function (painter, type, unit) {
|
|
263
|
+
var texture = painter.createTexture();
|
|
264
|
+
painter.activeTexture(painter['TEXTURE' + unit]);
|
|
265
|
+
painter.bindTexture(type, texture);
|
|
266
|
+
return texture;
|
|
267
|
+
};
|
|
268
|
+
var linkImage = function (painter, type, level, format, textureType, image) {
|
|
269
|
+
painter.texImage2D(type, level, format, format, textureType, image);
|
|
270
|
+
};
|
|
271
|
+
var linkCube = function (painter, type, level, format, textureType, images, width, height, texture) {
|
|
272
|
+
var types = [
|
|
273
|
+
painter.TEXTURE_CUBE_MAP_POSITIVE_X,
|
|
274
|
+
painter.TEXTURE_CUBE_MAP_NEGATIVE_X,
|
|
275
|
+
painter.TEXTURE_CUBE_MAP_POSITIVE_Y,
|
|
276
|
+
painter.TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
|
277
|
+
painter.TEXTURE_CUBE_MAP_POSITIVE_Z,
|
|
278
|
+
painter.TEXTURE_CUBE_MAP_NEGATIVE_Z
|
|
279
|
+
], target;
|
|
280
|
+
for (var i = 0; i < types.length; i++) {
|
|
281
|
+
if (images[i]) {
|
|
282
|
+
target = types[i];
|
|
283
|
+
painter.texImage2D(target, level, format, width, height, 0, format, textureType, null);
|
|
284
|
+
painter.bindTexture(type, texture);
|
|
285
|
+
painter.texImage2D(target, level, format, format, textureType, images[i]);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
painter.generateMipmap(type);
|
|
289
|
+
};
|
|
290
|
+
var TextureObject = (function () {
|
|
291
|
+
function TextureObject(painter, type, unit) {
|
|
292
|
+
if (unit === void 0) { unit = 0; }
|
|
293
|
+
this.__painter = painter;
|
|
294
|
+
this.__type = {
|
|
295
|
+
"2d": painter.TEXTURE_2D,
|
|
296
|
+
"cube": painter.TEXTURE_CUBE_MAP
|
|
297
|
+
}[type];
|
|
298
|
+
this.__texture = initTexture(painter, this.__type, unit);
|
|
299
|
+
painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
|
|
300
|
+
painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST);
|
|
301
|
+
painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
|
|
302
|
+
painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
|
|
303
|
+
}
|
|
304
|
+
TextureObject.prototype.useImage = function (image) {
|
|
305
|
+
linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image);
|
|
306
|
+
return this;
|
|
307
|
+
};
|
|
308
|
+
TextureObject.prototype.useCube = function (images, width, height) {
|
|
309
|
+
linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture);
|
|
310
|
+
return this;
|
|
311
|
+
};
|
|
312
|
+
return TextureObject;
|
|
313
313
|
}());
|
|
314
314
|
|
|
315
|
-
var textures = {};
|
|
316
|
-
function getTexture (type, painter, kind) {
|
|
317
|
-
var uniqueName = type + "-" + kind;
|
|
318
|
-
if (!textures[uniqueName]) {
|
|
319
|
-
textures[uniqueName] = new TextureObject(painter, kind);
|
|
320
|
-
}
|
|
321
|
-
return textures[uniqueName];
|
|
315
|
+
var textures = {};
|
|
316
|
+
function getTexture (type, painter, kind) {
|
|
317
|
+
var uniqueName = type + "-" + kind;
|
|
318
|
+
if (!textures[uniqueName]) {
|
|
319
|
+
textures[uniqueName] = new TextureObject(painter, kind);
|
|
320
|
+
}
|
|
321
|
+
return textures[uniqueName];
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
-
var loadShader = function (painter, type, source) {
|
|
325
|
-
var shader = painter.createShader(type);
|
|
326
|
-
if (shader == null)
|
|
327
|
-
throw new Error('Unable to create shader!');
|
|
328
|
-
painter.shaderSource(shader, source);
|
|
329
|
-
painter.compileShader(shader);
|
|
330
|
-
if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
|
|
331
|
-
throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader));
|
|
332
|
-
return shader;
|
|
333
|
-
};
|
|
334
|
-
var useShader = function (painter, vshaderSource, fshaderSource) {
|
|
335
|
-
var vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource);
|
|
336
|
-
var fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource);
|
|
337
|
-
var glProgram = painter.createProgram();
|
|
338
|
-
painter.attachShader(glProgram, vertexShader);
|
|
339
|
-
painter.attachShader(glProgram, fragmentShader);
|
|
340
|
-
painter.linkProgram(glProgram);
|
|
341
|
-
if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
|
|
342
|
-
throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram));
|
|
343
|
-
return glProgram;
|
|
344
|
-
};
|
|
345
|
-
var ShaderObject = (function () {
|
|
346
|
-
function ShaderObject(painter) {
|
|
347
|
-
this.__painter = painter;
|
|
348
|
-
}
|
|
349
|
-
ShaderObject.prototype.use = function () {
|
|
350
|
-
this.__painter.useProgram(this.program);
|
|
351
|
-
return this;
|
|
352
|
-
};
|
|
353
|
-
ShaderObject.prototype.compile = function (vshaderSource, fshaderSource) {
|
|
354
|
-
this.program = useShader(this.__painter, vshaderSource, fshaderSource);
|
|
355
|
-
return this;
|
|
356
|
-
};
|
|
357
|
-
return ShaderObject;
|
|
324
|
+
var loadShader = function (painter, type, source) {
|
|
325
|
+
var shader = painter.createShader(type);
|
|
326
|
+
if (shader == null)
|
|
327
|
+
throw new Error('Unable to create shader!');
|
|
328
|
+
painter.shaderSource(shader, source);
|
|
329
|
+
painter.compileShader(shader);
|
|
330
|
+
if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
|
|
331
|
+
throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader));
|
|
332
|
+
return shader;
|
|
333
|
+
};
|
|
334
|
+
var useShader = function (painter, vshaderSource, fshaderSource) {
|
|
335
|
+
var vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource);
|
|
336
|
+
var fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource);
|
|
337
|
+
var glProgram = painter.createProgram();
|
|
338
|
+
painter.attachShader(glProgram, vertexShader);
|
|
339
|
+
painter.attachShader(glProgram, fragmentShader);
|
|
340
|
+
painter.linkProgram(glProgram);
|
|
341
|
+
if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
|
|
342
|
+
throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram));
|
|
343
|
+
return glProgram;
|
|
344
|
+
};
|
|
345
|
+
var ShaderObject = (function () {
|
|
346
|
+
function ShaderObject(painter) {
|
|
347
|
+
this.__painter = painter;
|
|
348
|
+
}
|
|
349
|
+
ShaderObject.prototype.use = function () {
|
|
350
|
+
this.__painter.useProgram(this.program);
|
|
351
|
+
return this;
|
|
352
|
+
};
|
|
353
|
+
ShaderObject.prototype.compile = function (vshaderSource, fshaderSource) {
|
|
354
|
+
this.program = useShader(this.__painter, vshaderSource, fshaderSource);
|
|
355
|
+
return this;
|
|
356
|
+
};
|
|
357
|
+
return ShaderObject;
|
|
358
358
|
}());
|
|
359
359
|
|
|
360
|
-
var vsColor = "attribute vec4 a_position;\nuniform mat4 u_matrix;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n\n // 把原生的WebGL使用的左手坐标系变成了右手坐标系\n temp.z = -1.0 * temp.z;\n\n // 表示眼睛距离vec4(0.0,0.0,1.0)的距离\n float dist = 4.0;\n\n // 使用投影直接计算\n // 为保证纹理和相对位置正确\n // x、y、z的改变满足线性变换\n 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));\n}";
|
|
360
|
+
var vsColor = "attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n\r\n // 把原生的WebGL使用的左手坐标系变成了右手坐标系\r\n temp.z = -1.0 * temp.z;\r\n\r\n // 表示眼睛距离vec4(0.0,0.0,1.0)的距离\r\n float dist = 4.0;\r\n\r\n // 使用投影直接计算\r\n // 为保证纹理和相对位置正确\r\n // x、y、z的改变满足线性变换\r\n 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));\r\n}";
|
|
361
361
|
|
|
362
|
-
var vsColors = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec4 a_color;\nvarying vec4 v_color;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n 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));\n\n v_color = a_color;\n}";
|
|
362
|
+
var vsColors = "attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\nattribute vec4 a_color;\r\nvarying vec4 v_color;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n temp.z = -1.0 * temp.z;\r\n float dist = 4.0;\r\n 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));\r\n\r\n v_color = a_color;\r\n}";
|
|
363
363
|
|
|
364
|
-
var vsImage = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec2 a_textcoord;\nvarying vec2 v_textcoord;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n 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));\n\n v_textcoord = a_textcoord;\n}";
|
|
364
|
+
var vsImage = "attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\nattribute vec2 a_textcoord;\r\nvarying vec2 v_textcoord;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n temp.z = -1.0 * temp.z;\r\n float dist = 4.0;\r\n 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));\r\n\r\n v_textcoord = a_textcoord;\r\n}";
|
|
365
365
|
|
|
366
|
-
var vsCube = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec4 a_normal;\nvarying vec3 v_normal;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n 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));\n\n v_normal = normalize(vec3(a_normal));\n}";
|
|
366
|
+
var vsCube = "attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\nattribute vec4 a_normal;\r\nvarying vec3 v_normal;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n temp.z = -1.0 * temp.z;\r\n float dist = 4.0;\r\n 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));\r\n\r\n v_normal = normalize(vec3(a_normal));\r\n}";
|
|
367
367
|
|
|
368
|
-
var fsColor = "precision mediump float;\n\nuniform vec4 u_color;\n\nvoid main()\n{\n gl_FragColor = u_color;\n}";
|
|
368
|
+
var fsColor = "precision mediump float;\r\n\r\nuniform vec4 u_color;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = u_color;\r\n}";
|
|
369
369
|
|
|
370
|
-
var fsColors = "precision mediump float;\n\nvarying vec4 v_color;\n\nvoid main()\n{\n gl_FragColor = v_color;\n}";
|
|
370
|
+
var fsColors = "precision mediump float;\r\n\r\nvarying vec4 v_color;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = v_color;\r\n}";
|
|
371
371
|
|
|
372
|
-
var fsImage = "precision mediump float;\n\nuniform sampler2D u_sampler;\nvarying vec2 v_textcoord;\n\nvoid main()\n{\n gl_FragColor = texture2D(u_sampler, v_textcoord);\n}";
|
|
372
|
+
var fsImage = "precision mediump float;\r\n\r\nuniform sampler2D u_sampler;\r\nvarying vec2 v_textcoord;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = texture2D(u_sampler, v_textcoord);\r\n}";
|
|
373
373
|
|
|
374
|
-
var fsCube = "precision mediump float;\n\nvarying vec3 v_normal;\nuniform samplerCube u_texture;\n\nvoid main()\n{\n gl_FragColor = textureCube(u_texture, normalize(v_normal));\n}";
|
|
374
|
+
var fsCube = "precision mediump float;\r\n\r\nvarying vec3 v_normal;\r\nuniform samplerCube u_texture;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = textureCube(u_texture, normalize(v_normal));\r\n}";
|
|
375
375
|
|
|
376
|
-
var shaders = {};
|
|
377
|
-
function getShader (type, painter, mesh) {
|
|
378
|
-
var _a, _b;
|
|
379
|
-
var uniqueName = type +
|
|
380
|
-
(mesh.material.color ? "1" : "0") +
|
|
381
|
-
(mesh.material.colors ? "1" : "0") +
|
|
382
|
-
(mesh.material.image ? "1" : "0") +
|
|
383
|
-
(mesh.material.cube ? "1" : "0");
|
|
384
|
-
if (shaders[uniqueName])
|
|
385
|
-
return shaders[uniqueName].use();
|
|
386
|
-
var vertexShader = (_a = {},
|
|
387
|
-
_a[type + "1000"] = vsColor,
|
|
388
|
-
_a[type + "0100"] = vsColors,
|
|
389
|
-
_a[type + "0010"] = vsImage,
|
|
390
|
-
_a[type + "0001"] = vsCube,
|
|
391
|
-
_a)[uniqueName].replace(/uniform +mat4 +u_matrix;/, "\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;").replace(/u_matrix +\* +a_position/, "u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position");
|
|
392
|
-
var fragmentShader = (_b = {},
|
|
393
|
-
_b[type + "1000"] = fsColor,
|
|
394
|
-
_b[type + "0100"] = fsColors,
|
|
395
|
-
_b[type + "0010"] = fsImage,
|
|
396
|
-
_b[type + "0001"] = fsCube,
|
|
397
|
-
_b)[uniqueName];
|
|
398
|
-
var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
|
|
399
|
-
shaders[uniqueName] = shader;
|
|
400
|
-
return shader;
|
|
376
|
+
var shaders = {};
|
|
377
|
+
function getShader (type, painter, mesh) {
|
|
378
|
+
var _a, _b;
|
|
379
|
+
var uniqueName = type +
|
|
380
|
+
(mesh.material.color ? "1" : "0") +
|
|
381
|
+
(mesh.material.colors ? "1" : "0") +
|
|
382
|
+
(mesh.material.image ? "1" : "0") +
|
|
383
|
+
(mesh.material.cube ? "1" : "0");
|
|
384
|
+
if (shaders[uniqueName])
|
|
385
|
+
return shaders[uniqueName].use();
|
|
386
|
+
var vertexShader = (_a = {},
|
|
387
|
+
_a[type + "1000"] = vsColor,
|
|
388
|
+
_a[type + "0100"] = vsColors,
|
|
389
|
+
_a[type + "0010"] = vsImage,
|
|
390
|
+
_a[type + "0001"] = vsCube,
|
|
391
|
+
_a)[uniqueName].replace(/uniform +mat4 +u_matrix;/, "\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;").replace(/u_matrix +\* +a_position/, "u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position");
|
|
392
|
+
var fragmentShader = (_b = {},
|
|
393
|
+
_b[type + "1000"] = fsColor,
|
|
394
|
+
_b[type + "0100"] = fsColors,
|
|
395
|
+
_b[type + "0010"] = fsImage,
|
|
396
|
+
_b[type + "0001"] = fsCube,
|
|
397
|
+
_b)[uniqueName];
|
|
398
|
+
var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
|
|
399
|
+
shaders[uniqueName] = shader;
|
|
400
|
+
return shader;
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
function doDraw (type, painter, mesh, meshWorld, globalWorld) {
|
|
404
|
-
var shader = getShader(type, painter, mesh);
|
|
405
|
-
new BufferObject(painter).use()
|
|
406
|
-
.write(mesh.geometry.attributes.position.array)
|
|
407
|
-
.divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, mesh.geometry.attributes.position.itemSize, 0);
|
|
408
|
-
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix);
|
|
409
|
-
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_proporion"), false, globalWorld.proporion);
|
|
410
|
-
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_mesh"), false, meshWorld.matrix);
|
|
411
|
-
if (mesh.geometry.attributes.normal) {
|
|
412
|
-
new BufferObject(painter).use()
|
|
413
|
-
.write(mesh.geometry.attributes.normal.array)
|
|
414
|
-
.divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, mesh.geometry.attributes.normal.itemSize, 0);
|
|
415
|
-
}
|
|
416
|
-
if ("color" in mesh.material) {
|
|
417
|
-
painter.uniform4f(painter.getUniformLocation(shader.program, "u_color"), mesh.material.color.r, mesh.material.color.g, mesh.material.color.b, mesh.material.color.alpha);
|
|
418
|
-
}
|
|
419
|
-
if ("colors" in mesh.material) {
|
|
420
|
-
new BufferObject(painter).use()
|
|
421
|
-
.write(mesh.material.colors.array)
|
|
422
|
-
.divide(painter.getAttribLocation(shader.program, "a_color"), mesh.material.colors.itemSize, mesh.material.colors.itemSize, 0);
|
|
423
|
-
}
|
|
424
|
-
else if ("cube" in mesh.material) {
|
|
425
|
-
var size = mesh.material.cube.right.image.value.width;
|
|
426
|
-
painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0);
|
|
427
|
-
getTexture(type, painter, 'cube').useCube([
|
|
428
|
-
mesh.material.cube.right.image.value,
|
|
429
|
-
mesh.material.cube.left.image.value,
|
|
430
|
-
mesh.material.cube.top.image.value,
|
|
431
|
-
mesh.material.cube.bottom.image.value,
|
|
432
|
-
mesh.material.cube.far.image.value,
|
|
433
|
-
mesh.material.cube.near.image.value
|
|
434
|
-
], size, size);
|
|
435
|
-
}
|
|
436
|
-
else if ("image" in mesh.material) {
|
|
437
|
-
painter.uniform1i(painter.getUniformLocation(shader.program, "u_sampler"), 0);
|
|
438
|
-
new BufferObject(painter).use()
|
|
439
|
-
.write(mesh.geometry.attributes.uv.array)
|
|
440
|
-
.divide(painter.getAttribLocation(shader.program, "a_textcoord"), mesh.geometry.attributes.uv.itemSize, 2, 0);
|
|
441
|
-
getTexture(type, painter, '2d').useImage(mesh.material.image.value);
|
|
442
|
-
}
|
|
443
|
-
if (mesh.geometry.index) {
|
|
444
|
-
new BufferObject(painter, true).use()
|
|
445
|
-
.write(mesh.geometry.index.array);
|
|
446
|
-
painter.drawElements(painter[mesh.geometry.type], mesh.geometry.index.count, painter.UNSIGNED_BYTE, 0);
|
|
447
|
-
}
|
|
448
|
-
else {
|
|
449
|
-
painter.drawArrays(painter[mesh.geometry.type], 0, mesh.geometry.attributes.position.count);
|
|
450
|
-
}
|
|
403
|
+
function doDraw (type, painter, mesh, meshWorld, globalWorld) {
|
|
404
|
+
var shader = getShader(type, painter, mesh);
|
|
405
|
+
new BufferObject(painter).use()
|
|
406
|
+
.write(mesh.geometry.attributes.position.array)
|
|
407
|
+
.divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, mesh.geometry.attributes.position.itemSize, 0);
|
|
408
|
+
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix);
|
|
409
|
+
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_proporion"), false, globalWorld.proporion);
|
|
410
|
+
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_mesh"), false, meshWorld.matrix);
|
|
411
|
+
if (mesh.geometry.attributes.normal) {
|
|
412
|
+
new BufferObject(painter).use()
|
|
413
|
+
.write(mesh.geometry.attributes.normal.array)
|
|
414
|
+
.divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, mesh.geometry.attributes.normal.itemSize, 0);
|
|
415
|
+
}
|
|
416
|
+
if ("color" in mesh.material) {
|
|
417
|
+
painter.uniform4f(painter.getUniformLocation(shader.program, "u_color"), mesh.material.color.r, mesh.material.color.g, mesh.material.color.b, mesh.material.color.alpha);
|
|
418
|
+
}
|
|
419
|
+
if ("colors" in mesh.material) {
|
|
420
|
+
new BufferObject(painter).use()
|
|
421
|
+
.write(mesh.material.colors.array)
|
|
422
|
+
.divide(painter.getAttribLocation(shader.program, "a_color"), mesh.material.colors.itemSize, mesh.material.colors.itemSize, 0);
|
|
423
|
+
}
|
|
424
|
+
else if ("cube" in mesh.material) {
|
|
425
|
+
var size = mesh.material.cube.right.image.value.width;
|
|
426
|
+
painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0);
|
|
427
|
+
getTexture(type, painter, 'cube').useCube([
|
|
428
|
+
mesh.material.cube.right.image.value,
|
|
429
|
+
mesh.material.cube.left.image.value,
|
|
430
|
+
mesh.material.cube.top.image.value,
|
|
431
|
+
mesh.material.cube.bottom.image.value,
|
|
432
|
+
mesh.material.cube.far.image.value,
|
|
433
|
+
mesh.material.cube.near.image.value
|
|
434
|
+
], size, size);
|
|
435
|
+
}
|
|
436
|
+
else if ("image" in mesh.material) {
|
|
437
|
+
painter.uniform1i(painter.getUniformLocation(shader.program, "u_sampler"), 0);
|
|
438
|
+
new BufferObject(painter).use()
|
|
439
|
+
.write(mesh.geometry.attributes.uv.array)
|
|
440
|
+
.divide(painter.getAttribLocation(shader.program, "a_textcoord"), mesh.geometry.attributes.uv.itemSize, 2, 0);
|
|
441
|
+
getTexture(type, painter, '2d').useImage(mesh.material.image.value);
|
|
442
|
+
}
|
|
443
|
+
if (mesh.geometry.index) {
|
|
444
|
+
new BufferObject(painter, true).use()
|
|
445
|
+
.write(mesh.geometry.index.array);
|
|
446
|
+
painter.drawElements(painter[mesh.geometry.type], mesh.geometry.index.count, painter.UNSIGNED_BYTE, 0);
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
painter.drawArrays(painter[mesh.geometry.type], 0, mesh.geometry.attributes.position.count);
|
|
450
|
+
}
|
|
451
451
|
}
|
|
452
452
|
|
|
453
|
-
function assemble (begin, end, step, count) {
|
|
454
|
-
var val = [];
|
|
455
|
-
for (var index = 0; index < count; index++)
|
|
456
|
-
val[index] = begin;
|
|
457
|
-
return function () {
|
|
458
|
-
for (var i = 0; i < count; i++) {
|
|
459
|
-
if (val[i] + step < end) {
|
|
460
|
-
val[i] = +(val[i] + step).toFixed(7);
|
|
461
|
-
break;
|
|
462
|
-
}
|
|
463
|
-
else if (i < count - 1) {
|
|
464
|
-
val[i] = begin;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
return val;
|
|
468
|
-
};
|
|
453
|
+
function assemble (begin, end, step, count) {
|
|
454
|
+
var val = [];
|
|
455
|
+
for (var index = 0; index < count; index++)
|
|
456
|
+
val[index] = begin;
|
|
457
|
+
return function () {
|
|
458
|
+
for (var i = 0; i < count; i++) {
|
|
459
|
+
if (val[i] + step < end) {
|
|
460
|
+
val[i] = +(val[i] + step).toFixed(7);
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
else if (i < count - 1) {
|
|
464
|
+
val[i] = begin;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return val;
|
|
468
|
+
};
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
-
var needUpdate = false;
|
|
472
|
-
var scale = 10;
|
|
473
|
-
var WebGL$1 = (function () {
|
|
474
|
-
function WebGL(ViewCanvas, RegionCanvas) {
|
|
475
|
-
this.name = "WebGL";
|
|
476
|
-
this.__getColor = function (x, y) { return "rgba(0,0,0,1)"; };
|
|
477
|
-
this.__regionList = {};
|
|
478
|
-
this.__regionAssemble = assemble(0, 1, 0.2, 3);
|
|
479
|
-
this.__regionName = "";
|
|
480
|
-
this.__regionColor = [0, 0, 0, 1];
|
|
481
|
-
this.__scene = {
|
|
482
|
-
children: [],
|
|
483
|
-
matrix: new Matrix4([
|
|
484
|
-
1, 0, 0, 0,
|
|
485
|
-
0, 1, 0, 0,
|
|
486
|
-
0, 0, 1, 0,
|
|
487
|
-
0, 0, 0, scale
|
|
488
|
-
])
|
|
489
|
-
};
|
|
490
|
-
this.__unique = new Date().valueOf();
|
|
491
|
-
this.painter = getWebGLContext(ViewCanvas, scale);
|
|
492
|
-
if (RegionCanvas) {
|
|
493
|
-
this.__regionPainter = getWebGLContext(RegionCanvas, scale, {});
|
|
494
|
-
}
|
|
495
|
-
var proportion = this.painter.canvas.width / this.painter.canvas.height;
|
|
496
|
-
var xProportion = 1;
|
|
497
|
-
var yProportion = 1;
|
|
498
|
-
if (proportion > 1) {
|
|
499
|
-
xProportion = 1 / proportion;
|
|
500
|
-
}
|
|
501
|
-
else {
|
|
502
|
-
yProportion = proportion;
|
|
503
|
-
}
|
|
504
|
-
var zProportion = Math.min(xProportion, yProportion);
|
|
505
|
-
this.__proporion = [
|
|
506
|
-
xProportion, 0, 0, 0,
|
|
507
|
-
0, yProportion, 0, 0,
|
|
508
|
-
0, 0, zProportion, 0,
|
|
509
|
-
0, 0, 0, 1
|
|
510
|
-
];
|
|
511
|
-
}
|
|
512
|
-
WebGL.prototype.matrix = function (initMatrix4) {
|
|
513
|
-
return new Matrix4(initMatrix4);
|
|
514
|
-
};
|
|
515
|
-
WebGL.prototype.getMatrix = function () {
|
|
516
|
-
return this.__scene.matrix;
|
|
517
|
-
};
|
|
518
|
-
WebGL.prototype.getObject3D = function () {
|
|
519
|
-
return this.__scene.children;
|
|
520
|
-
};
|
|
521
|
-
WebGL.prototype.review = function (isUpdateRegion) {
|
|
522
|
-
if (isUpdateRegion === void 0) { isUpdateRegion = false; }
|
|
523
|
-
if (isUpdateRegion) {
|
|
524
|
-
if (this.__regionPainter) {
|
|
525
|
-
this.__regionPainter.clearColor(1, 1, 1, 1);
|
|
526
|
-
this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
this.painter.clearColor(1, 1, 1, 1);
|
|
531
|
-
this.painter.clear(this.painter.COLOR_BUFFER_BIT);
|
|
532
|
-
}
|
|
533
|
-
for (var index = 0; index < this.__scene.children.length; index++) {
|
|
534
|
-
this.draw(this.__scene.children[index], isUpdateRegion);
|
|
535
|
-
}
|
|
536
|
-
return this;
|
|
537
|
-
};
|
|
538
|
-
WebGL.prototype.draw = function (object3D, isUpdateRegion) {
|
|
539
|
-
if (isUpdateRegion === void 0) { isUpdateRegion = false; }
|
|
540
|
-
if (!isUpdateRegion)
|
|
541
|
-
needUpdate = true;
|
|
542
|
-
var meshWorld = {
|
|
543
|
-
matrix: object3D.matrix.value()
|
|
544
|
-
};
|
|
545
|
-
var globalWorld = {
|
|
546
|
-
matrix: this.__scene.matrix.value(),
|
|
547
|
-
proporion: this.__proporion
|
|
548
|
-
};
|
|
549
|
-
this.setRegion(object3D.region);
|
|
550
|
-
for (var index = 0; index < object3D.mesh.length; index++) {
|
|
551
|
-
if (isUpdateRegion) {
|
|
552
|
-
if (this.__regionPainter) {
|
|
553
|
-
doDraw("painter" + this.__unique, this.__regionPainter, {
|
|
554
|
-
geometry: object3D.mesh[index].geometry,
|
|
555
|
-
material: {
|
|
556
|
-
color: {
|
|
557
|
-
r: this.__regionColor[0],
|
|
558
|
-
g: this.__regionColor[1],
|
|
559
|
-
b: this.__regionColor[2],
|
|
560
|
-
alpha: this.__regionColor[3]
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
}, meshWorld, globalWorld);
|
|
564
|
-
this.__getColor = getColorFactory(this.__regionPainter);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
else {
|
|
568
|
-
doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
};
|
|
572
|
-
WebGL.prototype.render = function (object3D) {
|
|
573
|
-
if (!('matrix' in object3D))
|
|
574
|
-
object3D.matrix = new Matrix4();
|
|
575
|
-
if (!('region' in object3D))
|
|
576
|
-
object3D.region = "";
|
|
577
|
-
for (var index = 0; index < object3D.mesh.length; index++) {
|
|
578
|
-
var mesh = object3D.mesh[index];
|
|
579
|
-
if (mesh.geometry.attributes.normal && Array.isArray(mesh.geometry.attributes.normal.array)) {
|
|
580
|
-
mesh.geometry.attributes.normal.array = new Float32Array(mesh.geometry.attributes.normal.array);
|
|
581
|
-
}
|
|
582
|
-
if (mesh.geometry.attributes.position && Array.isArray(mesh.geometry.attributes.position.array)) {
|
|
583
|
-
mesh.geometry.attributes.position.array = new Float32Array(mesh.geometry.attributes.position.array);
|
|
584
|
-
}
|
|
585
|
-
if (mesh.geometry.attributes.uv && Array.isArray(mesh.geometry.attributes.uv.array)) {
|
|
586
|
-
mesh.geometry.attributes.uv.array = new Float32Array(mesh.geometry.attributes.uv.array);
|
|
587
|
-
}
|
|
588
|
-
if (mesh.geometry.index && Array.isArray(mesh.geometry.index.array)) {
|
|
589
|
-
mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array);
|
|
590
|
-
}
|
|
591
|
-
if (mesh.material.colors && Array.isArray(mesh.material.colors.array)) {
|
|
592
|
-
mesh.material.colors.array = new Float32Array(mesh.material.colors.array);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
this.__scene.children.push(object3D);
|
|
596
|
-
this.draw(object3D);
|
|
597
|
-
};
|
|
598
|
-
WebGL.prototype.setRegion = function (regionName) {
|
|
599
|
-
this.__regionName = regionName + "";
|
|
600
|
-
if (regionName) {
|
|
601
|
-
if (this.__regionList[regionName] == void 0) {
|
|
602
|
-
this.__regionList[regionName] = __spreadArray(__spreadArray([], this.__regionAssemble(), true), [1], false);
|
|
603
|
-
}
|
|
604
|
-
this.__regionColor = this.__regionList[regionName];
|
|
605
|
-
}
|
|
606
|
-
else {
|
|
607
|
-
this.__regionColor = [0, 0, 0, 1];
|
|
608
|
-
}
|
|
609
|
-
return this;
|
|
610
|
-
};
|
|
611
|
-
WebGL.prototype.getRegion = function (x, y) {
|
|
612
|
-
var _this = this;
|
|
613
|
-
if (needUpdate)
|
|
614
|
-
this.review(true);
|
|
615
|
-
needUpdate = false;
|
|
616
|
-
return new Promise(function (resolve, reject) {
|
|
617
|
-
var rgba = _this.__getColor(x, y);
|
|
618
|
-
for (var key in _this.__regionList) {
|
|
619
|
-
var currentRGBA = _this.__regionList[key];
|
|
620
|
-
if ("rgba(" + currentRGBA[0] * 255 + "," + currentRGBA[1] * 255 + "," + currentRGBA[2] * 255 + "," + currentRGBA[3] * 255 + ")" == rgba) {
|
|
621
|
-
resolve(key);
|
|
622
|
-
break;
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
resolve("");
|
|
626
|
-
});
|
|
627
|
-
};
|
|
628
|
-
return WebGL;
|
|
471
|
+
var needUpdate = false;
|
|
472
|
+
var scale = 10;
|
|
473
|
+
var WebGL$1 = (function () {
|
|
474
|
+
function WebGL(ViewCanvas, RegionCanvas) {
|
|
475
|
+
this.name = "WebGL";
|
|
476
|
+
this.__getColor = function (x, y) { return "rgba(0,0,0,1)"; };
|
|
477
|
+
this.__regionList = {};
|
|
478
|
+
this.__regionAssemble = assemble(0, 1, 0.2, 3);
|
|
479
|
+
this.__regionName = "";
|
|
480
|
+
this.__regionColor = [0, 0, 0, 1];
|
|
481
|
+
this.__scene = {
|
|
482
|
+
children: [],
|
|
483
|
+
matrix: new Matrix4([
|
|
484
|
+
1, 0, 0, 0,
|
|
485
|
+
0, 1, 0, 0,
|
|
486
|
+
0, 0, 1, 0,
|
|
487
|
+
0, 0, 0, scale
|
|
488
|
+
])
|
|
489
|
+
};
|
|
490
|
+
this.__unique = new Date().valueOf();
|
|
491
|
+
this.painter = getWebGLContext(ViewCanvas, scale);
|
|
492
|
+
if (RegionCanvas) {
|
|
493
|
+
this.__regionPainter = getWebGLContext(RegionCanvas, scale, {});
|
|
494
|
+
}
|
|
495
|
+
var proportion = this.painter.canvas.width / this.painter.canvas.height;
|
|
496
|
+
var xProportion = 1;
|
|
497
|
+
var yProportion = 1;
|
|
498
|
+
if (proportion > 1) {
|
|
499
|
+
xProportion = 1 / proportion;
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
yProportion = proportion;
|
|
503
|
+
}
|
|
504
|
+
var zProportion = Math.min(xProportion, yProportion);
|
|
505
|
+
this.__proporion = [
|
|
506
|
+
xProportion, 0, 0, 0,
|
|
507
|
+
0, yProportion, 0, 0,
|
|
508
|
+
0, 0, zProportion, 0,
|
|
509
|
+
0, 0, 0, 1
|
|
510
|
+
];
|
|
511
|
+
}
|
|
512
|
+
WebGL.prototype.matrix = function (initMatrix4) {
|
|
513
|
+
return new Matrix4(initMatrix4);
|
|
514
|
+
};
|
|
515
|
+
WebGL.prototype.getMatrix = function () {
|
|
516
|
+
return this.__scene.matrix;
|
|
517
|
+
};
|
|
518
|
+
WebGL.prototype.getObject3D = function () {
|
|
519
|
+
return this.__scene.children;
|
|
520
|
+
};
|
|
521
|
+
WebGL.prototype.review = function (isUpdateRegion) {
|
|
522
|
+
if (isUpdateRegion === void 0) { isUpdateRegion = false; }
|
|
523
|
+
if (isUpdateRegion) {
|
|
524
|
+
if (this.__regionPainter) {
|
|
525
|
+
this.__regionPainter.clearColor(1, 1, 1, 1);
|
|
526
|
+
this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
this.painter.clearColor(1, 1, 1, 1);
|
|
531
|
+
this.painter.clear(this.painter.COLOR_BUFFER_BIT);
|
|
532
|
+
}
|
|
533
|
+
for (var index = 0; index < this.__scene.children.length; index++) {
|
|
534
|
+
this.draw(this.__scene.children[index], isUpdateRegion);
|
|
535
|
+
}
|
|
536
|
+
return this;
|
|
537
|
+
};
|
|
538
|
+
WebGL.prototype.draw = function (object3D, isUpdateRegion) {
|
|
539
|
+
if (isUpdateRegion === void 0) { isUpdateRegion = false; }
|
|
540
|
+
if (!isUpdateRegion)
|
|
541
|
+
needUpdate = true;
|
|
542
|
+
var meshWorld = {
|
|
543
|
+
matrix: object3D.matrix.value()
|
|
544
|
+
};
|
|
545
|
+
var globalWorld = {
|
|
546
|
+
matrix: this.__scene.matrix.value(),
|
|
547
|
+
proporion: this.__proporion
|
|
548
|
+
};
|
|
549
|
+
this.setRegion(object3D.region);
|
|
550
|
+
for (var index = 0; index < object3D.mesh.length; index++) {
|
|
551
|
+
if (isUpdateRegion) {
|
|
552
|
+
if (this.__regionPainter) {
|
|
553
|
+
doDraw("painter" + this.__unique, this.__regionPainter, {
|
|
554
|
+
geometry: object3D.mesh[index].geometry,
|
|
555
|
+
material: {
|
|
556
|
+
color: {
|
|
557
|
+
r: this.__regionColor[0],
|
|
558
|
+
g: this.__regionColor[1],
|
|
559
|
+
b: this.__regionColor[2],
|
|
560
|
+
alpha: this.__regionColor[3]
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}, meshWorld, globalWorld);
|
|
564
|
+
this.__getColor = getColorFactory(this.__regionPainter);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
WebGL.prototype.render = function (object3D) {
|
|
573
|
+
if (!('matrix' in object3D))
|
|
574
|
+
object3D.matrix = new Matrix4();
|
|
575
|
+
if (!('region' in object3D))
|
|
576
|
+
object3D.region = "";
|
|
577
|
+
for (var index = 0; index < object3D.mesh.length; index++) {
|
|
578
|
+
var mesh = object3D.mesh[index];
|
|
579
|
+
if (mesh.geometry.attributes.normal && Array.isArray(mesh.geometry.attributes.normal.array)) {
|
|
580
|
+
mesh.geometry.attributes.normal.array = new Float32Array(mesh.geometry.attributes.normal.array);
|
|
581
|
+
}
|
|
582
|
+
if (mesh.geometry.attributes.position && Array.isArray(mesh.geometry.attributes.position.array)) {
|
|
583
|
+
mesh.geometry.attributes.position.array = new Float32Array(mesh.geometry.attributes.position.array);
|
|
584
|
+
}
|
|
585
|
+
if (mesh.geometry.attributes.uv && Array.isArray(mesh.geometry.attributes.uv.array)) {
|
|
586
|
+
mesh.geometry.attributes.uv.array = new Float32Array(mesh.geometry.attributes.uv.array);
|
|
587
|
+
}
|
|
588
|
+
if (mesh.geometry.index && Array.isArray(mesh.geometry.index.array)) {
|
|
589
|
+
mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array);
|
|
590
|
+
}
|
|
591
|
+
if (mesh.material.colors && Array.isArray(mesh.material.colors.array)) {
|
|
592
|
+
mesh.material.colors.array = new Float32Array(mesh.material.colors.array);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
this.__scene.children.push(object3D);
|
|
596
|
+
this.draw(object3D);
|
|
597
|
+
};
|
|
598
|
+
WebGL.prototype.setRegion = function (regionName) {
|
|
599
|
+
this.__regionName = regionName + "";
|
|
600
|
+
if (regionName) {
|
|
601
|
+
if (this.__regionList[regionName] == void 0) {
|
|
602
|
+
this.__regionList[regionName] = __spreadArray(__spreadArray([], this.__regionAssemble(), true), [1], false);
|
|
603
|
+
}
|
|
604
|
+
this.__regionColor = this.__regionList[regionName];
|
|
605
|
+
}
|
|
606
|
+
else {
|
|
607
|
+
this.__regionColor = [0, 0, 0, 1];
|
|
608
|
+
}
|
|
609
|
+
return this;
|
|
610
|
+
};
|
|
611
|
+
WebGL.prototype.getRegion = function (x, y) {
|
|
612
|
+
var _this = this;
|
|
613
|
+
if (needUpdate)
|
|
614
|
+
this.review(true);
|
|
615
|
+
needUpdate = false;
|
|
616
|
+
return new Promise(function (resolve, reject) {
|
|
617
|
+
var rgba = _this.__getColor(x, y);
|
|
618
|
+
for (var key in _this.__regionList) {
|
|
619
|
+
var currentRGBA = _this.__regionList[key];
|
|
620
|
+
if ("rgba(" + currentRGBA[0] * 255 + "," + currentRGBA[1] * 255 + "," + currentRGBA[2] * 255 + "," + currentRGBA[3] * 255 + ")" == rgba) {
|
|
621
|
+
resolve(key);
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
resolve("");
|
|
626
|
+
});
|
|
627
|
+
};
|
|
628
|
+
return WebGL;
|
|
629
629
|
}());
|
|
630
630
|
|
|
631
|
-
function mergeOption (option, defaultOption) {
|
|
632
|
-
for (var key in option) {
|
|
633
|
-
defaultOption[key] = option[key];
|
|
634
|
-
}
|
|
635
|
-
return defaultOption;
|
|
631
|
+
function mergeOption (option, defaultOption) {
|
|
632
|
+
for (var key in option) {
|
|
633
|
+
defaultOption[key] = option[key];
|
|
634
|
+
}
|
|
635
|
+
return defaultOption;
|
|
636
636
|
}
|
|
637
637
|
|
|
638
|
-
var WebGL = (function (_super) {
|
|
639
|
-
__extends(WebGL, _super);
|
|
640
|
-
function WebGL(el, option) {
|
|
641
|
-
if (option === void 0) { option = {}; }
|
|
642
|
-
if (!el) {
|
|
643
|
-
throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.");
|
|
644
|
-
}
|
|
645
|
-
option = mergeOption(option, {
|
|
646
|
-
region: true
|
|
647
|
-
});
|
|
648
|
-
var width = el.clientWidth, height = el.clientHeight;
|
|
649
|
-
var ViewCanvas, RegionCanvas;
|
|
650
|
-
var _el = el;
|
|
651
|
-
if (_el._vislite_canvas_) {
|
|
652
|
-
ViewCanvas = _el._vislite_canvas_[0];
|
|
653
|
-
RegionCanvas = _el._vislite_canvas_[1];
|
|
654
|
-
}
|
|
655
|
-
else {
|
|
656
|
-
if (option.region) {
|
|
657
|
-
RegionCanvas = document.createElement('canvas');
|
|
658
|
-
el.appendChild(RegionCanvas);
|
|
659
|
-
RegionCanvas.style.position = 'absolute';
|
|
660
|
-
RegionCanvas.style.zIndex = "-1";
|
|
661
|
-
RegionCanvas.style.opacity = "0";
|
|
662
|
-
}
|
|
663
|
-
ViewCanvas = document.createElement('canvas');
|
|
664
|
-
el.appendChild(ViewCanvas);
|
|
665
|
-
_el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
|
|
666
|
-
el.setAttribute('vislite', 'WebGL');
|
|
667
|
-
}
|
|
668
|
-
for (var _i = 0, _a = [ViewCanvas, RegionCanvas]; _i < _a.length; _i++) {
|
|
669
|
-
var canvas = _a[_i];
|
|
670
|
-
if (canvas) {
|
|
671
|
-
canvas.style.width = width + "px";
|
|
672
|
-
canvas.setAttribute('width', width + "");
|
|
673
|
-
canvas.style.height = height + "px";
|
|
674
|
-
canvas.setAttribute('height', height + "");
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
return _super.call(this, ViewCanvas, RegionCanvas) || this;
|
|
678
|
-
}
|
|
679
|
-
return WebGL;
|
|
638
|
+
var WebGL = (function (_super) {
|
|
639
|
+
__extends(WebGL, _super);
|
|
640
|
+
function WebGL(el, option) {
|
|
641
|
+
if (option === void 0) { option = {}; }
|
|
642
|
+
if (!el) {
|
|
643
|
+
throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.");
|
|
644
|
+
}
|
|
645
|
+
option = mergeOption(option, {
|
|
646
|
+
region: true
|
|
647
|
+
});
|
|
648
|
+
var width = el.clientWidth, height = el.clientHeight;
|
|
649
|
+
var ViewCanvas, RegionCanvas;
|
|
650
|
+
var _el = el;
|
|
651
|
+
if (_el._vislite_canvas_) {
|
|
652
|
+
ViewCanvas = _el._vislite_canvas_[0];
|
|
653
|
+
RegionCanvas = _el._vislite_canvas_[1];
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
if (option.region) {
|
|
657
|
+
RegionCanvas = document.createElement('canvas');
|
|
658
|
+
el.appendChild(RegionCanvas);
|
|
659
|
+
RegionCanvas.style.position = 'absolute';
|
|
660
|
+
RegionCanvas.style.zIndex = "-1";
|
|
661
|
+
RegionCanvas.style.opacity = "0";
|
|
662
|
+
}
|
|
663
|
+
ViewCanvas = document.createElement('canvas');
|
|
664
|
+
el.appendChild(ViewCanvas);
|
|
665
|
+
_el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
|
|
666
|
+
el.setAttribute('vislite', 'WebGL');
|
|
667
|
+
}
|
|
668
|
+
for (var _i = 0, _a = [ViewCanvas, RegionCanvas]; _i < _a.length; _i++) {
|
|
669
|
+
var canvas = _a[_i];
|
|
670
|
+
if (canvas) {
|
|
671
|
+
canvas.style.width = width + "px";
|
|
672
|
+
canvas.setAttribute('width', width + "");
|
|
673
|
+
canvas.style.height = height + "px";
|
|
674
|
+
canvas.setAttribute('height', height + "");
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
return _super.call(this, ViewCanvas, RegionCanvas) || this;
|
|
678
|
+
}
|
|
679
|
+
return WebGL;
|
|
680
680
|
}(WebGL$1));
|
|
681
681
|
|
|
682
682
|
return WebGL;
|