vislite 0.8.0 → 0.8.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG +212 -209
- package/README.md +136 -144
- package/lib/Buffer/index.umd.js +36 -36
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +691 -691
- package/lib/Canvas/index.umd.min.js +2 -2
- package/lib/Cardinal/index.umd.js +91 -91
- package/lib/Cardinal/index.umd.min.js +2 -2
- package/lib/Eoap/index.umd.js +34 -34
- package/lib/Eoap/index.umd.min.js +2 -2
- package/lib/Geometry/index.umd.js +286 -286
- package/lib/Geometry/index.umd.min.js +2 -2
- package/lib/Hermite/index.umd.js +36 -36
- package/lib/Hermite/index.umd.min.js +2 -2
- package/lib/Matrix4/index.umd.js +125 -125
- package/lib/Matrix4/index.umd.min.js +2 -2
- package/lib/Mercator/index.umd.js +20 -20
- package/lib/Mercator/index.umd.min.js +2 -2
- package/lib/OralCanvas/index.es.js +634 -634
- package/lib/OralCanvas/index.es.min.js +2 -2
- package/lib/OralWebGL/index.es.js +552 -552
- package/lib/OralWebGL/index.es.min.js +2 -2
- package/lib/SVG/index.umd.js +471 -471
- package/lib/SVG/index.umd.min.js +2 -2
- package/lib/Shader/index.umd.js +61 -61
- package/lib/Shader/index.umd.min.js +2 -2
- package/lib/Texture/index.umd.js +54 -54
- package/lib/Texture/index.umd.min.js +2 -2
- package/lib/TreeLayout/index.umd.js +368 -368
- package/lib/TreeLayout/index.umd.min.js +2 -2
- package/lib/WebGL/index.umd.js +599 -599
- package/lib/WebGL/index.umd.min.js +2 -2
- package/lib/animation/index.umd.js +73 -73
- package/lib/animation/index.umd.min.js +2 -2
- package/lib/formatColor/index.umd.js +40 -40
- package/lib/formatColor/index.umd.min.js +2 -2
- package/lib/getLoopColors/index.umd.js +36 -36
- package/lib/getLoopColors/index.umd.min.js +2 -2
- package/lib/getWebGLContext/index.umd.js +63 -63
- package/lib/getWebGLContext/index.umd.min.js +2 -2
- package/lib/index.umd.js +2955 -2955
- package/lib/index.umd.min.js +2 -2
- package/lib/move/index.umd.js +8 -8
- package/lib/move/index.umd.min.js +2 -2
- package/lib/resizeObserver/index.umd.js +30 -30
- package/lib/resizeObserver/index.umd.min.js +2 -2
- package/lib/rotate/index.umd.js +8 -8
- package/lib/rotate/index.umd.min.js +2 -2
- package/lib/ruler/index.umd.js +138 -138
- package/lib/ruler/index.umd.min.js +2 -2
- package/lib/scale/index.umd.js +7 -7
- package/lib/scale/index.umd.min.js +2 -2
- package/lib/throttle/index.umd.js +49 -49
- package/lib/throttle/index.umd.min.js +2 -2
- package/lib/viewHandler/index.umd.js +120 -120
- package/lib/viewHandler/index.umd.min.js +2 -2
- package/miniprogram/ui-canvas/drawImage.js +34 -0
- package/miniprogram/ui-canvas/index.js +10 -2
- package/package/getWebGLContext/index.ts +40 -40
- package/package.json +70 -70
- package/src/Canvas.ts +72 -72
- package/src/Geometry.ts +210 -210
- package/src/WebGL.ts +66 -66
- package/src/common/canvas/index.ts +183 -183
- package/src/common/canvas/painter.ts +446 -446
- package/src/common/geometry/prism-horizontal.ts +50 -50
- package/src/common/geometry/prism-vertical.ts +55 -55
- package/src/common/geometry/tool/circle.ts +17 -17
- package/src/common/geometry/tool/rotateLine.ts +48 -48
- package/src/common/geometry/tool/triangles.ts +23 -23
- package/src/common/webgl/getWebGLContext.ts +45 -45
- package/src/common/webgl/index.ts +227 -227
- package/types/Canvas.d.ts +318 -318
- package/types/Geometry.d.ts +132 -132
- package/types/WebGLOption.d.ts +14 -14
- package/types/getWebGLContext.d.ts +4 -4
- package/types/ui-canvas.d.ts +4 -4
- package/uni-app/drawImage.js +17 -17
- package/uni-app/ui-canvas.vue +290 -290
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.8.0
|
|
2
|
+
* VISLite JavaScript Library v0.8.1-alpha.0
|
|
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: Tue Apr 02 2024 14:46:44 GMT+0800 (China Standard Time)
|
|
10
10
|
*/
|
|
11
11
|
/******************************************************************************
|
|
12
12
|
Copyright (c) Microsoft Corporation.
|
|
@@ -40,327 +40,327 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
40
40
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
function getWebGLContext (canvas, scale, opts, mode) {
|
|
44
|
-
if (opts === void 0) { opts = {}; }
|
|
45
|
-
if (mode === void 0) { mode = "scaleToFill"; }
|
|
46
|
-
var names = ["experimental-webgl", "webkit-3d", "moz-webgl"];
|
|
47
|
-
var painter = canvas.getContext("webgl", opts);
|
|
48
|
-
for (var i = 0; i < names.length; i++) {
|
|
49
|
-
try {
|
|
50
|
-
painter = canvas.getContext(names[i], opts);
|
|
51
|
-
}
|
|
52
|
-
catch (e) { }
|
|
53
|
-
if (painter)
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
if (!painter)
|
|
57
|
-
throw new Error('Non canvas or browser does not support webgl.');
|
|
58
|
-
var width = painter.canvas.width, height = painter.canvas.height;
|
|
59
|
-
var scaleX = scale, scaleY = scale;
|
|
60
|
-
if (mode == "aspectFit") {
|
|
61
|
-
if (width > height) {
|
|
62
|
-
scaleX *= height / width;
|
|
63
|
-
}
|
|
64
|
-
else if (height > width) {
|
|
65
|
-
scaleY *= width / height;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else if (mode == "aspectFill") {
|
|
69
|
-
if (width > height) {
|
|
70
|
-
scaleY *= width / height;
|
|
71
|
-
}
|
|
72
|
-
else if (height > width) {
|
|
73
|
-
scaleX *= height / width;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
var viewWidth = width * scaleX;
|
|
77
|
-
var viewHeight = height * scaleY;
|
|
78
|
-
painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight);
|
|
79
|
-
painter.depthFunc(painter.LEQUAL);
|
|
80
|
-
painter.enable(painter.DEPTH_TEST);
|
|
81
|
-
return painter;
|
|
43
|
+
function getWebGLContext (canvas, scale, opts, mode) {
|
|
44
|
+
if (opts === void 0) { opts = {}; }
|
|
45
|
+
if (mode === void 0) { mode = "scaleToFill"; }
|
|
46
|
+
var names = ["experimental-webgl", "webkit-3d", "moz-webgl"];
|
|
47
|
+
var painter = canvas.getContext("webgl", opts);
|
|
48
|
+
for (var i = 0; i < names.length; i++) {
|
|
49
|
+
try {
|
|
50
|
+
painter = canvas.getContext(names[i], opts);
|
|
51
|
+
}
|
|
52
|
+
catch (e) { }
|
|
53
|
+
if (painter)
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
if (!painter)
|
|
57
|
+
throw new Error('Non canvas or browser does not support webgl.');
|
|
58
|
+
var width = painter.canvas.width, height = painter.canvas.height;
|
|
59
|
+
var scaleX = scale, scaleY = scale;
|
|
60
|
+
if (mode == "aspectFit") {
|
|
61
|
+
if (width > height) {
|
|
62
|
+
scaleX *= height / width;
|
|
63
|
+
}
|
|
64
|
+
else if (height > width) {
|
|
65
|
+
scaleY *= width / height;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (mode == "aspectFill") {
|
|
69
|
+
if (width > height) {
|
|
70
|
+
scaleY *= width / height;
|
|
71
|
+
}
|
|
72
|
+
else if (height > width) {
|
|
73
|
+
scaleX *= height / width;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
var viewWidth = width * scaleX;
|
|
77
|
+
var viewHeight = height * scaleY;
|
|
78
|
+
painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight);
|
|
79
|
+
painter.depthFunc(painter.LEQUAL);
|
|
80
|
+
painter.enable(painter.DEPTH_TEST);
|
|
81
|
+
return painter;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
function getColorFactory (painter) {
|
|
85
|
-
var width = painter.drawingBufferWidth, height = painter.drawingBufferHeight;
|
|
86
|
-
var pixels = new Uint8Array(4 * width * height);
|
|
87
|
-
painter.readPixels(0, 0, width, height, painter.RGBA, painter.UNSIGNED_BYTE, pixels);
|
|
88
|
-
return function (x, y) {
|
|
89
|
-
y = height - y;
|
|
90
|
-
var pixelR = pixels[4 * (y * width + x)];
|
|
91
|
-
var pixelG = pixels[4 * (y * width + x) + 1];
|
|
92
|
-
var pixelB = pixels[4 * (y * width + x) + 2];
|
|
93
|
-
var pixelA = pixels[4 * (y * width + x) + 3];
|
|
94
|
-
return "rgba(" + pixelR + "," + pixelG + "," + pixelB + "," + pixelA + ")";
|
|
95
|
-
};
|
|
84
|
+
function getColorFactory (painter) {
|
|
85
|
+
var width = painter.drawingBufferWidth, height = painter.drawingBufferHeight;
|
|
86
|
+
var pixels = new Uint8Array(4 * width * height);
|
|
87
|
+
painter.readPixels(0, 0, width, height, painter.RGBA, painter.UNSIGNED_BYTE, pixels);
|
|
88
|
+
return function (x, y) {
|
|
89
|
+
y = height - y;
|
|
90
|
+
var pixelR = pixels[4 * (y * width + x)];
|
|
91
|
+
var pixelG = pixels[4 * (y * width + x) + 1];
|
|
92
|
+
var pixelB = pixels[4 * (y * width + x) + 2];
|
|
93
|
+
var pixelA = pixels[4 * (y * width + x) + 3];
|
|
94
|
+
return "rgba(" + pixelR + "," + pixelG + "," + pixelB + "," + pixelA + ")";
|
|
95
|
+
};
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
function _move (d, a, b, c) {
|
|
99
|
-
if (c === void 0) { c = 0; }
|
|
100
|
-
var sqrt = Math.sqrt(a * a + b * b + c * c);
|
|
101
|
-
return [
|
|
102
|
-
1, 0, 0, 0,
|
|
103
|
-
0, 1, 0, 0,
|
|
104
|
-
0, 0, 1, 0,
|
|
105
|
-
a * d / sqrt, b * d / sqrt, c * d / sqrt, 1
|
|
106
|
-
];
|
|
98
|
+
function _move (d, a, b, c) {
|
|
99
|
+
if (c === void 0) { c = 0; }
|
|
100
|
+
var sqrt = Math.sqrt(a * a + b * b + c * c);
|
|
101
|
+
return [
|
|
102
|
+
1, 0, 0, 0,
|
|
103
|
+
0, 1, 0, 0,
|
|
104
|
+
0, 0, 1, 0,
|
|
105
|
+
a * d / sqrt, b * d / sqrt, c * d / sqrt, 1
|
|
106
|
+
];
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
function _rotate (deg) {
|
|
110
|
-
var sin = Math.sin(deg), cos = Math.cos(deg);
|
|
111
|
-
return [
|
|
112
|
-
cos, sin, 0, 0,
|
|
113
|
-
-sin, cos, 0, 0,
|
|
114
|
-
0, 0, 1, 0,
|
|
115
|
-
0, 0, 0, 1
|
|
116
|
-
];
|
|
109
|
+
function _rotate (deg) {
|
|
110
|
+
var sin = Math.sin(deg), cos = Math.cos(deg);
|
|
111
|
+
return [
|
|
112
|
+
cos, sin, 0, 0,
|
|
113
|
+
-sin, cos, 0, 0,
|
|
114
|
+
0, 0, 1, 0,
|
|
115
|
+
0, 0, 0, 1
|
|
116
|
+
];
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
function _scale (xTimes, yTimes, zTimes, cx, cy, cz) {
|
|
120
|
-
if (cx === void 0) { cx = 0; }
|
|
121
|
-
if (cy === void 0) { cy = 0; }
|
|
122
|
-
if (cz === void 0) { cz = 0; }
|
|
123
|
-
return [
|
|
124
|
-
xTimes, 0, 0, 0,
|
|
125
|
-
0, yTimes, 0, 0,
|
|
126
|
-
0, 0, zTimes, 0,
|
|
127
|
-
cx - cx * xTimes, cy - cy * yTimes, cz - cz * zTimes, 1
|
|
128
|
-
];
|
|
119
|
+
function _scale (xTimes, yTimes, zTimes, cx, cy, cz) {
|
|
120
|
+
if (cx === void 0) { cx = 0; }
|
|
121
|
+
if (cy === void 0) { cy = 0; }
|
|
122
|
+
if (cz === void 0) { cz = 0; }
|
|
123
|
+
return [
|
|
124
|
+
xTimes, 0, 0, 0,
|
|
125
|
+
0, yTimes, 0, 0,
|
|
126
|
+
0, 0, zTimes, 0,
|
|
127
|
+
cx - cx * xTimes, cy - cy * yTimes, cz - cz * zTimes, 1
|
|
128
|
+
];
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
function _transform (a1, b1, c1, a2, b2, c2) {
|
|
132
|
-
if (typeof a1 === 'number' && typeof b1 === 'number') {
|
|
133
|
-
if (typeof c1 !== 'number') {
|
|
134
|
-
c1 = 0;
|
|
135
|
-
a2 = a1;
|
|
136
|
-
b2 = b1;
|
|
137
|
-
c2 = 1;
|
|
138
|
-
}
|
|
139
|
-
else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
|
|
140
|
-
a2 = a1;
|
|
141
|
-
b2 = b1;
|
|
142
|
-
c2 = c1;
|
|
143
|
-
a1 = 0;
|
|
144
|
-
b1 = 0;
|
|
145
|
-
c1 = 0;
|
|
146
|
-
}
|
|
147
|
-
if (a1 == a2 && b1 == b2 && c1 == c2)
|
|
148
|
-
throw new Error('It\'s not a legitimate ray!');
|
|
149
|
-
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;
|
|
150
|
-
return [
|
|
151
|
-
[
|
|
152
|
-
cos1, cos2 * sin1, sin1 * sin2, 0,
|
|
153
|
-
-sin1, cos1 * cos2, cos1 * sin2, 0,
|
|
154
|
-
0, -sin2, cos2, 0,
|
|
155
|
-
b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
|
|
156
|
-
],
|
|
157
|
-
[
|
|
158
|
-
cos1, -sin1, 0, 0,
|
|
159
|
-
cos2 * sin1, cos2 * cos1, -sin2, 0,
|
|
160
|
-
sin1 * sin2, cos1 * sin2, cos2, 0,
|
|
161
|
-
a1, b1, c1, 1
|
|
162
|
-
]
|
|
163
|
-
];
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
throw new Error('a1 and b1 is required!');
|
|
167
|
-
}
|
|
131
|
+
function _transform (a1, b1, c1, a2, b2, c2) {
|
|
132
|
+
if (typeof a1 === 'number' && typeof b1 === 'number') {
|
|
133
|
+
if (typeof c1 !== 'number') {
|
|
134
|
+
c1 = 0;
|
|
135
|
+
a2 = a1;
|
|
136
|
+
b2 = b1;
|
|
137
|
+
c2 = 1;
|
|
138
|
+
}
|
|
139
|
+
else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
|
|
140
|
+
a2 = a1;
|
|
141
|
+
b2 = b1;
|
|
142
|
+
c2 = c1;
|
|
143
|
+
a1 = 0;
|
|
144
|
+
b1 = 0;
|
|
145
|
+
c1 = 0;
|
|
146
|
+
}
|
|
147
|
+
if (a1 == a2 && b1 == b2 && c1 == c2)
|
|
148
|
+
throw new Error('It\'s not a legitimate ray!');
|
|
149
|
+
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;
|
|
150
|
+
return [
|
|
151
|
+
[
|
|
152
|
+
cos1, cos2 * sin1, sin1 * sin2, 0,
|
|
153
|
+
-sin1, cos1 * cos2, cos1 * sin2, 0,
|
|
154
|
+
0, -sin2, cos2, 0,
|
|
155
|
+
b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
|
|
156
|
+
],
|
|
157
|
+
[
|
|
158
|
+
cos1, -sin1, 0, 0,
|
|
159
|
+
cos2 * sin1, cos2 * cos1, -sin2, 0,
|
|
160
|
+
sin1 * sin2, cos1 * sin2, cos2, 0,
|
|
161
|
+
a1, b1, c1, 1
|
|
162
|
+
]
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
throw new Error('a1 and b1 is required!');
|
|
167
|
+
}
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
var _multiply = function (matrix4, param) {
|
|
171
|
-
var newParam = [];
|
|
172
|
-
for (var i = 0; i < 4; i++)
|
|
173
|
-
for (var j = 0; j < param.length / 4; j++)
|
|
174
|
-
newParam[j * 4 + i] =
|
|
175
|
-
matrix4[i] * param[j * 4] +
|
|
176
|
-
matrix4[i + 4] * param[j * 4 + 1] +
|
|
177
|
-
matrix4[i + 8] * param[j * 4 + 2] +
|
|
178
|
-
matrix4[i + 12] * param[j * 4 + 3];
|
|
179
|
-
return newParam;
|
|
180
|
-
};
|
|
181
|
-
var __initMatrix4 = [
|
|
182
|
-
1, 0, 0, 0,
|
|
183
|
-
0, 1, 0, 0,
|
|
184
|
-
0, 0, 1, 0,
|
|
185
|
-
0, 0, 0, 1
|
|
186
|
-
];
|
|
187
|
-
var Matrix4 = (function () {
|
|
188
|
-
function Matrix4(initMatrix4) {
|
|
189
|
-
if (initMatrix4 === void 0) { initMatrix4 = __initMatrix4; }
|
|
190
|
-
this.name = 'Matrix4';
|
|
191
|
-
this.__matrix4 = initMatrix4;
|
|
192
|
-
}
|
|
193
|
-
Matrix4.prototype.setValue = function (initMatrix4) {
|
|
194
|
-
if (initMatrix4 === void 0) { initMatrix4 = __initMatrix4; }
|
|
195
|
-
this.__matrix4 = initMatrix4;
|
|
196
|
-
return this;
|
|
197
|
-
};
|
|
198
|
-
Matrix4.prototype.move = function (dis, a, b, c) {
|
|
199
|
-
if (c === void 0) { c = 0; }
|
|
200
|
-
this.__matrix4 = _multiply(_move(dis, a, b, c), this.__matrix4);
|
|
201
|
-
return this;
|
|
202
|
-
};
|
|
203
|
-
Matrix4.prototype.rotate = function (deg, a1, b1, c1, a2, b2, c2) {
|
|
204
|
-
var matrix4s = _transform(a1, b1, c1, a2, b2, c2);
|
|
205
|
-
this.__matrix4 = _multiply(_multiply(_multiply(matrix4s[1], _rotate(deg)), matrix4s[0]), this.__matrix4);
|
|
206
|
-
return this;
|
|
207
|
-
};
|
|
208
|
-
Matrix4.prototype.scale = function (xTimes, yTimes, zTimes, cx, cy, cz) {
|
|
209
|
-
if (cx === void 0) { cx = 0; }
|
|
210
|
-
if (cy === void 0) { cy = 0; }
|
|
211
|
-
if (cz === void 0) { cz = 0; }
|
|
212
|
-
this.__matrix4 = _multiply(_scale(xTimes, yTimes, zTimes, cx, cy, cz), this.__matrix4);
|
|
213
|
-
return this;
|
|
214
|
-
};
|
|
215
|
-
Matrix4.prototype.multiply = function (newMatrix4, flag) {
|
|
216
|
-
if (flag === void 0) { flag = false; }
|
|
217
|
-
this.__matrix4 = flag ? _multiply(this.__matrix4, newMatrix4) : _multiply(newMatrix4, this.__matrix4);
|
|
218
|
-
return this;
|
|
219
|
-
};
|
|
220
|
-
Matrix4.prototype.use = function (x, y, z, w) {
|
|
221
|
-
if (z === void 0) { z = 0; }
|
|
222
|
-
if (w === void 0) { w = 1; }
|
|
223
|
-
return _multiply(this.__matrix4, [x, y, z, w]);
|
|
224
|
-
};
|
|
225
|
-
Matrix4.prototype.value = function () {
|
|
226
|
-
return this.__matrix4;
|
|
227
|
-
};
|
|
228
|
-
return Matrix4;
|
|
170
|
+
var _multiply = function (matrix4, param) {
|
|
171
|
+
var newParam = [];
|
|
172
|
+
for (var i = 0; i < 4; i++)
|
|
173
|
+
for (var j = 0; j < param.length / 4; j++)
|
|
174
|
+
newParam[j * 4 + i] =
|
|
175
|
+
matrix4[i] * param[j * 4] +
|
|
176
|
+
matrix4[i + 4] * param[j * 4 + 1] +
|
|
177
|
+
matrix4[i + 8] * param[j * 4 + 2] +
|
|
178
|
+
matrix4[i + 12] * param[j * 4 + 3];
|
|
179
|
+
return newParam;
|
|
180
|
+
};
|
|
181
|
+
var __initMatrix4 = [
|
|
182
|
+
1, 0, 0, 0,
|
|
183
|
+
0, 1, 0, 0,
|
|
184
|
+
0, 0, 1, 0,
|
|
185
|
+
0, 0, 0, 1
|
|
186
|
+
];
|
|
187
|
+
var Matrix4 = (function () {
|
|
188
|
+
function Matrix4(initMatrix4) {
|
|
189
|
+
if (initMatrix4 === void 0) { initMatrix4 = __initMatrix4; }
|
|
190
|
+
this.name = 'Matrix4';
|
|
191
|
+
this.__matrix4 = initMatrix4;
|
|
192
|
+
}
|
|
193
|
+
Matrix4.prototype.setValue = function (initMatrix4) {
|
|
194
|
+
if (initMatrix4 === void 0) { initMatrix4 = __initMatrix4; }
|
|
195
|
+
this.__matrix4 = initMatrix4;
|
|
196
|
+
return this;
|
|
197
|
+
};
|
|
198
|
+
Matrix4.prototype.move = function (dis, a, b, c) {
|
|
199
|
+
if (c === void 0) { c = 0; }
|
|
200
|
+
this.__matrix4 = _multiply(_move(dis, a, b, c), this.__matrix4);
|
|
201
|
+
return this;
|
|
202
|
+
};
|
|
203
|
+
Matrix4.prototype.rotate = function (deg, a1, b1, c1, a2, b2, c2) {
|
|
204
|
+
var matrix4s = _transform(a1, b1, c1, a2, b2, c2);
|
|
205
|
+
this.__matrix4 = _multiply(_multiply(_multiply(matrix4s[1], _rotate(deg)), matrix4s[0]), this.__matrix4);
|
|
206
|
+
return this;
|
|
207
|
+
};
|
|
208
|
+
Matrix4.prototype.scale = function (xTimes, yTimes, zTimes, cx, cy, cz) {
|
|
209
|
+
if (cx === void 0) { cx = 0; }
|
|
210
|
+
if (cy === void 0) { cy = 0; }
|
|
211
|
+
if (cz === void 0) { cz = 0; }
|
|
212
|
+
this.__matrix4 = _multiply(_scale(xTimes, yTimes, zTimes, cx, cy, cz), this.__matrix4);
|
|
213
|
+
return this;
|
|
214
|
+
};
|
|
215
|
+
Matrix4.prototype.multiply = function (newMatrix4, flag) {
|
|
216
|
+
if (flag === void 0) { flag = false; }
|
|
217
|
+
this.__matrix4 = flag ? _multiply(this.__matrix4, newMatrix4) : _multiply(newMatrix4, this.__matrix4);
|
|
218
|
+
return this;
|
|
219
|
+
};
|
|
220
|
+
Matrix4.prototype.use = function (x, y, z, w) {
|
|
221
|
+
if (z === void 0) { z = 0; }
|
|
222
|
+
if (w === void 0) { w = 1; }
|
|
223
|
+
return _multiply(this.__matrix4, [x, y, z, w]);
|
|
224
|
+
};
|
|
225
|
+
Matrix4.prototype.value = function () {
|
|
226
|
+
return this.__matrix4;
|
|
227
|
+
};
|
|
228
|
+
return Matrix4;
|
|
229
229
|
}());
|
|
230
230
|
|
|
231
|
-
var newBuffer = function (painter) {
|
|
232
|
-
return painter.createBuffer();
|
|
233
|
-
};
|
|
234
|
-
var writeBuffer = function (painter, data, isElement, usage) {
|
|
235
|
-
var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
|
|
236
|
-
painter.bufferData(TYPE, data, usage);
|
|
237
|
-
};
|
|
238
|
-
var useBuffer = function (painter, location, size, type, stride, offset, normalized) {
|
|
239
|
-
painter.vertexAttribPointer(location, size, type, normalized, stride, offset);
|
|
240
|
-
painter.enableVertexAttribArray(location);
|
|
241
|
-
};
|
|
242
|
-
var BufferObject = (function () {
|
|
243
|
-
function BufferObject(painter, isElement) {
|
|
244
|
-
if (isElement === void 0) { isElement = false; }
|
|
245
|
-
this.__painter = painter;
|
|
246
|
-
this.__isElement = isElement;
|
|
247
|
-
this.__buffer = newBuffer(painter);
|
|
248
|
-
this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
|
|
249
|
-
}
|
|
250
|
-
BufferObject.prototype.use = function () {
|
|
251
|
-
this.__painter.bindBuffer(this.__type, this.__buffer);
|
|
252
|
-
return this;
|
|
253
|
-
};
|
|
254
|
-
BufferObject.prototype.write = function (data) {
|
|
255
|
-
writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW);
|
|
256
|
-
this.__fsize = data.BYTES_PER_ELEMENT;
|
|
257
|
-
return this;
|
|
258
|
-
};
|
|
259
|
-
BufferObject.prototype.divide = function (location, size, stride, offset) {
|
|
260
|
-
if (offset === void 0) { offset = 0; }
|
|
261
|
-
useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false);
|
|
262
|
-
return this;
|
|
263
|
-
};
|
|
264
|
-
return BufferObject;
|
|
231
|
+
var newBuffer = function (painter) {
|
|
232
|
+
return painter.createBuffer();
|
|
233
|
+
};
|
|
234
|
+
var writeBuffer = function (painter, data, isElement, usage) {
|
|
235
|
+
var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
|
|
236
|
+
painter.bufferData(TYPE, data, usage);
|
|
237
|
+
};
|
|
238
|
+
var useBuffer = function (painter, location, size, type, stride, offset, normalized) {
|
|
239
|
+
painter.vertexAttribPointer(location, size, type, normalized, stride, offset);
|
|
240
|
+
painter.enableVertexAttribArray(location);
|
|
241
|
+
};
|
|
242
|
+
var BufferObject = (function () {
|
|
243
|
+
function BufferObject(painter, isElement) {
|
|
244
|
+
if (isElement === void 0) { isElement = false; }
|
|
245
|
+
this.__painter = painter;
|
|
246
|
+
this.__isElement = isElement;
|
|
247
|
+
this.__buffer = newBuffer(painter);
|
|
248
|
+
this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
|
|
249
|
+
}
|
|
250
|
+
BufferObject.prototype.use = function () {
|
|
251
|
+
this.__painter.bindBuffer(this.__type, this.__buffer);
|
|
252
|
+
return this;
|
|
253
|
+
};
|
|
254
|
+
BufferObject.prototype.write = function (data) {
|
|
255
|
+
writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW);
|
|
256
|
+
this.__fsize = data.BYTES_PER_ELEMENT;
|
|
257
|
+
return this;
|
|
258
|
+
};
|
|
259
|
+
BufferObject.prototype.divide = function (location, size, stride, offset) {
|
|
260
|
+
if (offset === void 0) { offset = 0; }
|
|
261
|
+
useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false);
|
|
262
|
+
return this;
|
|
263
|
+
};
|
|
264
|
+
return BufferObject;
|
|
265
265
|
}());
|
|
266
266
|
|
|
267
|
-
var initTexture = function (painter, type, unit) {
|
|
268
|
-
var texture = painter.createTexture();
|
|
269
|
-
painter.activeTexture(painter['TEXTURE' + unit]);
|
|
270
|
-
painter.bindTexture(type, texture);
|
|
271
|
-
return texture;
|
|
272
|
-
};
|
|
273
|
-
var linkImage = function (painter, type, level, format, textureType, image) {
|
|
274
|
-
painter.texImage2D(type, level, format, format, textureType, image);
|
|
275
|
-
};
|
|
276
|
-
var linkCube = function (painter, type, level, format, textureType, images, width, height, texture) {
|
|
277
|
-
var types = [
|
|
278
|
-
painter.TEXTURE_CUBE_MAP_POSITIVE_X,
|
|
279
|
-
painter.TEXTURE_CUBE_MAP_NEGATIVE_X,
|
|
280
|
-
painter.TEXTURE_CUBE_MAP_POSITIVE_Y,
|
|
281
|
-
painter.TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
|
282
|
-
painter.TEXTURE_CUBE_MAP_POSITIVE_Z,
|
|
283
|
-
painter.TEXTURE_CUBE_MAP_NEGATIVE_Z
|
|
284
|
-
];
|
|
285
|
-
var target;
|
|
286
|
-
for (var i = 0; i < types.length; i++) {
|
|
287
|
-
if (images[i]) {
|
|
288
|
-
target = types[i];
|
|
289
|
-
painter.texImage2D(target, level, format, width, height, 0, format, textureType, null);
|
|
290
|
-
painter.bindTexture(type, texture);
|
|
291
|
-
painter.texImage2D(target, level, format, format, textureType, images[i]);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
painter.generateMipmap(type);
|
|
295
|
-
};
|
|
296
|
-
var TextureObject = (function () {
|
|
297
|
-
function TextureObject(painter, type, unit) {
|
|
298
|
-
if (unit === void 0) { unit = 0; }
|
|
299
|
-
this.__painter = painter;
|
|
300
|
-
this.__type = {
|
|
301
|
-
"2d": painter.TEXTURE_2D,
|
|
302
|
-
"cube": painter.TEXTURE_CUBE_MAP
|
|
303
|
-
}[type];
|
|
304
|
-
this.__texture = initTexture(painter, this.__type, unit);
|
|
305
|
-
painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
|
|
306
|
-
painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST);
|
|
307
|
-
painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
|
|
308
|
-
painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
|
|
309
|
-
}
|
|
310
|
-
TextureObject.prototype.useImage = function (image) {
|
|
311
|
-
linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image);
|
|
312
|
-
return this;
|
|
313
|
-
};
|
|
314
|
-
TextureObject.prototype.useCube = function (images, width, height) {
|
|
315
|
-
linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture);
|
|
316
|
-
return this;
|
|
317
|
-
};
|
|
318
|
-
return TextureObject;
|
|
267
|
+
var initTexture = function (painter, type, unit) {
|
|
268
|
+
var texture = painter.createTexture();
|
|
269
|
+
painter.activeTexture(painter['TEXTURE' + unit]);
|
|
270
|
+
painter.bindTexture(type, texture);
|
|
271
|
+
return texture;
|
|
272
|
+
};
|
|
273
|
+
var linkImage = function (painter, type, level, format, textureType, image) {
|
|
274
|
+
painter.texImage2D(type, level, format, format, textureType, image);
|
|
275
|
+
};
|
|
276
|
+
var linkCube = function (painter, type, level, format, textureType, images, width, height, texture) {
|
|
277
|
+
var types = [
|
|
278
|
+
painter.TEXTURE_CUBE_MAP_POSITIVE_X,
|
|
279
|
+
painter.TEXTURE_CUBE_MAP_NEGATIVE_X,
|
|
280
|
+
painter.TEXTURE_CUBE_MAP_POSITIVE_Y,
|
|
281
|
+
painter.TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
|
282
|
+
painter.TEXTURE_CUBE_MAP_POSITIVE_Z,
|
|
283
|
+
painter.TEXTURE_CUBE_MAP_NEGATIVE_Z
|
|
284
|
+
];
|
|
285
|
+
var target;
|
|
286
|
+
for (var i = 0; i < types.length; i++) {
|
|
287
|
+
if (images[i]) {
|
|
288
|
+
target = types[i];
|
|
289
|
+
painter.texImage2D(target, level, format, width, height, 0, format, textureType, null);
|
|
290
|
+
painter.bindTexture(type, texture);
|
|
291
|
+
painter.texImage2D(target, level, format, format, textureType, images[i]);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
painter.generateMipmap(type);
|
|
295
|
+
};
|
|
296
|
+
var TextureObject = (function () {
|
|
297
|
+
function TextureObject(painter, type, unit) {
|
|
298
|
+
if (unit === void 0) { unit = 0; }
|
|
299
|
+
this.__painter = painter;
|
|
300
|
+
this.__type = {
|
|
301
|
+
"2d": painter.TEXTURE_2D,
|
|
302
|
+
"cube": painter.TEXTURE_CUBE_MAP
|
|
303
|
+
}[type];
|
|
304
|
+
this.__texture = initTexture(painter, this.__type, unit);
|
|
305
|
+
painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
|
|
306
|
+
painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST);
|
|
307
|
+
painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
|
|
308
|
+
painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
|
|
309
|
+
}
|
|
310
|
+
TextureObject.prototype.useImage = function (image) {
|
|
311
|
+
linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image);
|
|
312
|
+
return this;
|
|
313
|
+
};
|
|
314
|
+
TextureObject.prototype.useCube = function (images, width, height) {
|
|
315
|
+
linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture);
|
|
316
|
+
return this;
|
|
317
|
+
};
|
|
318
|
+
return TextureObject;
|
|
319
319
|
}());
|
|
320
320
|
|
|
321
|
-
var textures = {};
|
|
322
|
-
function getTexture (type, painter, kind) {
|
|
323
|
-
var uniqueName = type + "-" + kind;
|
|
324
|
-
if (!textures[uniqueName]) {
|
|
325
|
-
textures[uniqueName] = new TextureObject(painter, kind);
|
|
326
|
-
}
|
|
327
|
-
return textures[uniqueName];
|
|
321
|
+
var textures = {};
|
|
322
|
+
function getTexture (type, painter, kind) {
|
|
323
|
+
var uniqueName = type + "-" + kind;
|
|
324
|
+
if (!textures[uniqueName]) {
|
|
325
|
+
textures[uniqueName] = new TextureObject(painter, kind);
|
|
326
|
+
}
|
|
327
|
+
return textures[uniqueName];
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
-
var loadShader = function (painter, type, source) {
|
|
331
|
-
var shader = painter.createShader(type);
|
|
332
|
-
if (shader == null)
|
|
333
|
-
throw new Error('Unable to create shader!');
|
|
334
|
-
painter.shaderSource(shader, source);
|
|
335
|
-
painter.compileShader(shader);
|
|
336
|
-
if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
|
|
337
|
-
throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader));
|
|
338
|
-
return shader;
|
|
339
|
-
};
|
|
340
|
-
var useShader = function (painter, vshaderSource, fshaderSource) {
|
|
341
|
-
var vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource);
|
|
342
|
-
var fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource);
|
|
343
|
-
var glProgram = painter.createProgram();
|
|
344
|
-
painter.attachShader(glProgram, vertexShader);
|
|
345
|
-
painter.attachShader(glProgram, fragmentShader);
|
|
346
|
-
painter.linkProgram(glProgram);
|
|
347
|
-
if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
|
|
348
|
-
throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram));
|
|
349
|
-
return glProgram;
|
|
350
|
-
};
|
|
351
|
-
var ShaderObject = (function () {
|
|
352
|
-
function ShaderObject(painter) {
|
|
353
|
-
this.__painter = painter;
|
|
354
|
-
}
|
|
355
|
-
ShaderObject.prototype.use = function () {
|
|
356
|
-
this.__painter.useProgram(this.program);
|
|
357
|
-
return this;
|
|
358
|
-
};
|
|
359
|
-
ShaderObject.prototype.compile = function (vshaderSource, fshaderSource) {
|
|
360
|
-
this.program = useShader(this.__painter, vshaderSource, fshaderSource);
|
|
361
|
-
return this;
|
|
362
|
-
};
|
|
363
|
-
return ShaderObject;
|
|
330
|
+
var loadShader = function (painter, type, source) {
|
|
331
|
+
var shader = painter.createShader(type);
|
|
332
|
+
if (shader == null)
|
|
333
|
+
throw new Error('Unable to create shader!');
|
|
334
|
+
painter.shaderSource(shader, source);
|
|
335
|
+
painter.compileShader(shader);
|
|
336
|
+
if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
|
|
337
|
+
throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader));
|
|
338
|
+
return shader;
|
|
339
|
+
};
|
|
340
|
+
var useShader = function (painter, vshaderSource, fshaderSource) {
|
|
341
|
+
var vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource);
|
|
342
|
+
var fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource);
|
|
343
|
+
var glProgram = painter.createProgram();
|
|
344
|
+
painter.attachShader(glProgram, vertexShader);
|
|
345
|
+
painter.attachShader(glProgram, fragmentShader);
|
|
346
|
+
painter.linkProgram(glProgram);
|
|
347
|
+
if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
|
|
348
|
+
throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram));
|
|
349
|
+
return glProgram;
|
|
350
|
+
};
|
|
351
|
+
var ShaderObject = (function () {
|
|
352
|
+
function ShaderObject(painter) {
|
|
353
|
+
this.__painter = painter;
|
|
354
|
+
}
|
|
355
|
+
ShaderObject.prototype.use = function () {
|
|
356
|
+
this.__painter.useProgram(this.program);
|
|
357
|
+
return this;
|
|
358
|
+
};
|
|
359
|
+
ShaderObject.prototype.compile = function (vshaderSource, fshaderSource) {
|
|
360
|
+
this.program = useShader(this.__painter, vshaderSource, fshaderSource);
|
|
361
|
+
return this;
|
|
362
|
+
};
|
|
363
|
+
return ShaderObject;
|
|
364
364
|
}());
|
|
365
365
|
|
|
366
366
|
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}";
|
|
@@ -379,261 +379,261 @@ var fsImage = "precision mediump float;\n\nuniform sampler2D u_sampler;\nvarying
|
|
|
379
379
|
|
|
380
380
|
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}";
|
|
381
381
|
|
|
382
|
-
var shaders = {};
|
|
383
|
-
function getShader (type, painter, mesh) {
|
|
384
|
-
var _a, _b;
|
|
385
|
-
var uniqueName = type +
|
|
386
|
-
(mesh.material.color ? "1" : "0") +
|
|
387
|
-
(mesh.material.colors ? "1" : "0") +
|
|
388
|
-
(mesh.material.image ? "1" : "0") +
|
|
389
|
-
(mesh.material.cube ? "1" : "0");
|
|
390
|
-
if (shaders[uniqueName])
|
|
391
|
-
return shaders[uniqueName].use();
|
|
392
|
-
var vertexShader = (_a = {},
|
|
393
|
-
_a[type + "1000"] = vsColor,
|
|
394
|
-
_a[type + "0100"] = vsColors,
|
|
395
|
-
_a[type + "0010"] = vsImage,
|
|
396
|
-
_a[type + "0001"] = vsCube,
|
|
397
|
-
_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");
|
|
398
|
-
var fragmentShader = (_b = {},
|
|
399
|
-
_b[type + "1000"] = fsColor,
|
|
400
|
-
_b[type + "0100"] = fsColors,
|
|
401
|
-
_b[type + "0010"] = fsImage,
|
|
402
|
-
_b[type + "0001"] = fsCube,
|
|
403
|
-
_b)[uniqueName];
|
|
404
|
-
var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
|
|
405
|
-
shaders[uniqueName] = shader;
|
|
406
|
-
return shader;
|
|
382
|
+
var shaders = {};
|
|
383
|
+
function getShader (type, painter, mesh) {
|
|
384
|
+
var _a, _b;
|
|
385
|
+
var uniqueName = type +
|
|
386
|
+
(mesh.material.color ? "1" : "0") +
|
|
387
|
+
(mesh.material.colors ? "1" : "0") +
|
|
388
|
+
(mesh.material.image ? "1" : "0") +
|
|
389
|
+
(mesh.material.cube ? "1" : "0");
|
|
390
|
+
if (shaders[uniqueName])
|
|
391
|
+
return shaders[uniqueName].use();
|
|
392
|
+
var vertexShader = (_a = {},
|
|
393
|
+
_a[type + "1000"] = vsColor,
|
|
394
|
+
_a[type + "0100"] = vsColors,
|
|
395
|
+
_a[type + "0010"] = vsImage,
|
|
396
|
+
_a[type + "0001"] = vsCube,
|
|
397
|
+
_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");
|
|
398
|
+
var fragmentShader = (_b = {},
|
|
399
|
+
_b[type + "1000"] = fsColor,
|
|
400
|
+
_b[type + "0100"] = fsColors,
|
|
401
|
+
_b[type + "0010"] = fsImage,
|
|
402
|
+
_b[type + "0001"] = fsCube,
|
|
403
|
+
_b)[uniqueName];
|
|
404
|
+
var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
|
|
405
|
+
shaders[uniqueName] = shader;
|
|
406
|
+
return shader;
|
|
407
407
|
}
|
|
408
408
|
|
|
409
|
-
function doDraw (type, painter, mesh, meshWorld, globalWorld) {
|
|
410
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
411
|
-
var shader = getShader(type, painter, mesh);
|
|
412
|
-
new BufferObject(painter).use()
|
|
413
|
-
.write(mesh.geometry.attributes.position.array)
|
|
414
|
-
.divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, mesh.geometry.attributes.position.itemSize, 0);
|
|
415
|
-
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix);
|
|
416
|
-
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_proporion"), false, globalWorld.proporion);
|
|
417
|
-
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_mesh"), false, meshWorld.matrix);
|
|
418
|
-
if (mesh.geometry.attributes.normal) {
|
|
419
|
-
new BufferObject(painter).use()
|
|
420
|
-
.write(mesh.geometry.attributes.normal.array)
|
|
421
|
-
.divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, mesh.geometry.attributes.normal.itemSize, 0);
|
|
422
|
-
}
|
|
423
|
-
if ("color" in mesh.material) {
|
|
424
|
-
painter.uniform4f(painter.getUniformLocation(shader.program, "u_color"), (_a = mesh.material.color) === null || _a === void 0 ? void 0 : _a.r, (_b = mesh.material.color) === null || _b === void 0 ? void 0 : _b.g, (_c = mesh.material.color) === null || _c === void 0 ? void 0 : _c.b, (_d = mesh.material.color) === null || _d === void 0 ? void 0 : _d.alpha);
|
|
425
|
-
}
|
|
426
|
-
if ("colors" in mesh.material) {
|
|
427
|
-
new BufferObject(painter).use()
|
|
428
|
-
.write((_e = mesh.material.colors) === null || _e === void 0 ? void 0 : _e.array)
|
|
429
|
-
.divide(painter.getAttribLocation(shader.program, "a_color"), (_f = mesh.material.colors) === null || _f === void 0 ? void 0 : _f.itemSize, (_g = mesh.material.colors) === null || _g === void 0 ? void 0 : _g.itemSize, 0);
|
|
430
|
-
}
|
|
431
|
-
else if ("cube" in mesh.material) {
|
|
432
|
-
var size = ((_j = (_h = mesh.material.cube) === null || _h === void 0 ? void 0 : _h.right) === null || _j === void 0 ? void 0 : _j.image.value).width;
|
|
433
|
-
painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0);
|
|
434
|
-
getTexture(type, painter, 'cube').useCube([
|
|
435
|
-
(_l = (_k = mesh.material.cube) === null || _k === void 0 ? void 0 : _k.right) === null || _l === void 0 ? void 0 : _l.image.value,
|
|
436
|
-
(_o = (_m = mesh.material.cube) === null || _m === void 0 ? void 0 : _m.left) === null || _o === void 0 ? void 0 : _o.image.value,
|
|
437
|
-
(_q = (_p = mesh.material.cube) === null || _p === void 0 ? void 0 : _p.top) === null || _q === void 0 ? void 0 : _q.image.value,
|
|
438
|
-
(_s = (_r = mesh.material.cube) === null || _r === void 0 ? void 0 : _r.bottom) === null || _s === void 0 ? void 0 : _s.image.value,
|
|
439
|
-
(_u = (_t = mesh.material.cube) === null || _t === void 0 ? void 0 : _t.far) === null || _u === void 0 ? void 0 : _u.image.value,
|
|
440
|
-
(_w = (_v = mesh.material.cube) === null || _v === void 0 ? void 0 : _v.near) === null || _w === void 0 ? void 0 : _w.image.value
|
|
441
|
-
], size, size);
|
|
442
|
-
}
|
|
443
|
-
else if ("image" in mesh.material) {
|
|
444
|
-
painter.uniform1i(painter.getUniformLocation(shader.program, "u_sampler"), 0);
|
|
445
|
-
new BufferObject(painter).use()
|
|
446
|
-
.write((_x = mesh.geometry.attributes.uv) === null || _x === void 0 ? void 0 : _x.array)
|
|
447
|
-
.divide(painter.getAttribLocation(shader.program, "a_textcoord"), (_y = mesh.geometry.attributes.uv) === null || _y === void 0 ? void 0 : _y.itemSize, 2, 0);
|
|
448
|
-
getTexture(type, painter, '2d').useImage((_z = mesh.material.image) === null || _z === void 0 ? void 0 : _z.value);
|
|
449
|
-
}
|
|
450
|
-
if (mesh.geometry.index) {
|
|
451
|
-
new BufferObject(painter, true).use()
|
|
452
|
-
.write(mesh.geometry.index.array);
|
|
453
|
-
painter.drawElements(painter[mesh.geometry.type], mesh.geometry.index.count, painter.UNSIGNED_BYTE, 0);
|
|
454
|
-
}
|
|
455
|
-
else {
|
|
456
|
-
painter.drawArrays(painter[mesh.geometry.type], 0, mesh.geometry.attributes.position.count);
|
|
457
|
-
}
|
|
409
|
+
function doDraw (type, painter, mesh, meshWorld, globalWorld) {
|
|
410
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
411
|
+
var shader = getShader(type, painter, mesh);
|
|
412
|
+
new BufferObject(painter).use()
|
|
413
|
+
.write(mesh.geometry.attributes.position.array)
|
|
414
|
+
.divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, mesh.geometry.attributes.position.itemSize, 0);
|
|
415
|
+
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix);
|
|
416
|
+
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_proporion"), false, globalWorld.proporion);
|
|
417
|
+
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_mesh"), false, meshWorld.matrix);
|
|
418
|
+
if (mesh.geometry.attributes.normal) {
|
|
419
|
+
new BufferObject(painter).use()
|
|
420
|
+
.write(mesh.geometry.attributes.normal.array)
|
|
421
|
+
.divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, mesh.geometry.attributes.normal.itemSize, 0);
|
|
422
|
+
}
|
|
423
|
+
if ("color" in mesh.material) {
|
|
424
|
+
painter.uniform4f(painter.getUniformLocation(shader.program, "u_color"), (_a = mesh.material.color) === null || _a === void 0 ? void 0 : _a.r, (_b = mesh.material.color) === null || _b === void 0 ? void 0 : _b.g, (_c = mesh.material.color) === null || _c === void 0 ? void 0 : _c.b, (_d = mesh.material.color) === null || _d === void 0 ? void 0 : _d.alpha);
|
|
425
|
+
}
|
|
426
|
+
if ("colors" in mesh.material) {
|
|
427
|
+
new BufferObject(painter).use()
|
|
428
|
+
.write((_e = mesh.material.colors) === null || _e === void 0 ? void 0 : _e.array)
|
|
429
|
+
.divide(painter.getAttribLocation(shader.program, "a_color"), (_f = mesh.material.colors) === null || _f === void 0 ? void 0 : _f.itemSize, (_g = mesh.material.colors) === null || _g === void 0 ? void 0 : _g.itemSize, 0);
|
|
430
|
+
}
|
|
431
|
+
else if ("cube" in mesh.material) {
|
|
432
|
+
var size = ((_j = (_h = mesh.material.cube) === null || _h === void 0 ? void 0 : _h.right) === null || _j === void 0 ? void 0 : _j.image.value).width;
|
|
433
|
+
painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0);
|
|
434
|
+
getTexture(type, painter, 'cube').useCube([
|
|
435
|
+
(_l = (_k = mesh.material.cube) === null || _k === void 0 ? void 0 : _k.right) === null || _l === void 0 ? void 0 : _l.image.value,
|
|
436
|
+
(_o = (_m = mesh.material.cube) === null || _m === void 0 ? void 0 : _m.left) === null || _o === void 0 ? void 0 : _o.image.value,
|
|
437
|
+
(_q = (_p = mesh.material.cube) === null || _p === void 0 ? void 0 : _p.top) === null || _q === void 0 ? void 0 : _q.image.value,
|
|
438
|
+
(_s = (_r = mesh.material.cube) === null || _r === void 0 ? void 0 : _r.bottom) === null || _s === void 0 ? void 0 : _s.image.value,
|
|
439
|
+
(_u = (_t = mesh.material.cube) === null || _t === void 0 ? void 0 : _t.far) === null || _u === void 0 ? void 0 : _u.image.value,
|
|
440
|
+
(_w = (_v = mesh.material.cube) === null || _v === void 0 ? void 0 : _v.near) === null || _w === void 0 ? void 0 : _w.image.value
|
|
441
|
+
], size, size);
|
|
442
|
+
}
|
|
443
|
+
else if ("image" in mesh.material) {
|
|
444
|
+
painter.uniform1i(painter.getUniformLocation(shader.program, "u_sampler"), 0);
|
|
445
|
+
new BufferObject(painter).use()
|
|
446
|
+
.write((_x = mesh.geometry.attributes.uv) === null || _x === void 0 ? void 0 : _x.array)
|
|
447
|
+
.divide(painter.getAttribLocation(shader.program, "a_textcoord"), (_y = mesh.geometry.attributes.uv) === null || _y === void 0 ? void 0 : _y.itemSize, 2, 0);
|
|
448
|
+
getTexture(type, painter, '2d').useImage((_z = mesh.material.image) === null || _z === void 0 ? void 0 : _z.value);
|
|
449
|
+
}
|
|
450
|
+
if (mesh.geometry.index) {
|
|
451
|
+
new BufferObject(painter, true).use()
|
|
452
|
+
.write(mesh.geometry.index.array);
|
|
453
|
+
painter.drawElements(painter[mesh.geometry.type], mesh.geometry.index.count, painter.UNSIGNED_BYTE, 0);
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
painter.drawArrays(painter[mesh.geometry.type], 0, mesh.geometry.attributes.position.count);
|
|
457
|
+
}
|
|
458
458
|
}
|
|
459
459
|
|
|
460
|
-
function assemble (begin, end, step, count) {
|
|
461
|
-
var val = [];
|
|
462
|
-
for (var index = 0; index < count; index++)
|
|
463
|
-
val[index] = begin;
|
|
464
|
-
return function () {
|
|
465
|
-
for (var i = 0; i < count; i++) {
|
|
466
|
-
if (val[i] + step < end) {
|
|
467
|
-
val[i] = +(val[i] + step).toFixed(7);
|
|
468
|
-
break;
|
|
469
|
-
}
|
|
470
|
-
else if (i < count - 1) {
|
|
471
|
-
val[i] = begin;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
return val;
|
|
475
|
-
};
|
|
460
|
+
function assemble (begin, end, step, count) {
|
|
461
|
+
var val = [];
|
|
462
|
+
for (var index = 0; index < count; index++)
|
|
463
|
+
val[index] = begin;
|
|
464
|
+
return function () {
|
|
465
|
+
for (var i = 0; i < count; i++) {
|
|
466
|
+
if (val[i] + step < end) {
|
|
467
|
+
val[i] = +(val[i] + step).toFixed(7);
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
else if (i < count - 1) {
|
|
471
|
+
val[i] = begin;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return val;
|
|
475
|
+
};
|
|
476
476
|
}
|
|
477
477
|
|
|
478
|
-
var needUpdate = false;
|
|
479
|
-
var scale = 10;
|
|
480
|
-
var WebGL = (function () {
|
|
481
|
-
function WebGL(ViewCanvas, RegionCanvas, mode) {
|
|
482
|
-
this.name = "WebGL";
|
|
483
|
-
this.__getColor = function (x, y) { return "rgba(0,0,0,1)"; };
|
|
484
|
-
this.__regionList = {};
|
|
485
|
-
this.__regionAssemble = assemble(0, 1, 0.2, 3);
|
|
486
|
-
this.__regionName = "";
|
|
487
|
-
this.__regionColor = [0, 0, 0, 1];
|
|
488
|
-
this.__scene = {
|
|
489
|
-
children: [],
|
|
490
|
-
matrix: new Matrix4([
|
|
491
|
-
1, 0, 0, 0,
|
|
492
|
-
0, 1, 0, 0,
|
|
493
|
-
0, 0, 1, 0,
|
|
494
|
-
0, 0, 0, scale
|
|
495
|
-
])
|
|
496
|
-
};
|
|
497
|
-
this.__unique = new Date().valueOf();
|
|
498
|
-
this.painter = getWebGLContext(ViewCanvas, scale, {}, mode);
|
|
499
|
-
if (RegionCanvas) {
|
|
500
|
-
this.__regionPainter = getWebGLContext(RegionCanvas, scale, {}, mode);
|
|
501
|
-
}
|
|
502
|
-
var proportion = this.painter.canvas.width / this.painter.canvas.height;
|
|
503
|
-
var xProportion = 1;
|
|
504
|
-
var yProportion = 1;
|
|
505
|
-
if (proportion > 1) {
|
|
506
|
-
xProportion = 1 / proportion;
|
|
507
|
-
}
|
|
508
|
-
else {
|
|
509
|
-
yProportion = proportion;
|
|
510
|
-
}
|
|
511
|
-
var zProportion = Math.min(xProportion, yProportion);
|
|
512
|
-
this.__proporion = [
|
|
513
|
-
xProportion, 0, 0, 0,
|
|
514
|
-
0, yProportion, 0, 0,
|
|
515
|
-
0, 0, zProportion, 0,
|
|
516
|
-
0, 0, 0, 1
|
|
517
|
-
];
|
|
518
|
-
}
|
|
519
|
-
WebGL.prototype.matrix = function (initMatrix4) {
|
|
520
|
-
return new Matrix4(initMatrix4);
|
|
521
|
-
};
|
|
522
|
-
WebGL.prototype.getMatrix = function () {
|
|
523
|
-
return this.__scene.matrix;
|
|
524
|
-
};
|
|
525
|
-
WebGL.prototype.getObject3D = function () {
|
|
526
|
-
return this.__scene.children;
|
|
527
|
-
};
|
|
528
|
-
WebGL.prototype.review = function (isUpdateRegion) {
|
|
529
|
-
if (isUpdateRegion === void 0) { isUpdateRegion = false; }
|
|
530
|
-
if (isUpdateRegion) {
|
|
531
|
-
if (this.__regionPainter) {
|
|
532
|
-
this.__regionPainter.clearColor(1, 1, 1, 1);
|
|
533
|
-
this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
else {
|
|
537
|
-
this.painter.clearColor(1, 1, 1, 1);
|
|
538
|
-
this.painter.clear(this.painter.COLOR_BUFFER_BIT);
|
|
539
|
-
}
|
|
540
|
-
for (var index = 0; index < this.__scene.children.length; index++) {
|
|
541
|
-
this.draw(this.__scene.children[index], isUpdateRegion);
|
|
542
|
-
}
|
|
543
|
-
return this;
|
|
544
|
-
};
|
|
545
|
-
WebGL.prototype.draw = function (object3D, isUpdateRegion) {
|
|
546
|
-
var _a;
|
|
547
|
-
if (isUpdateRegion === void 0) { isUpdateRegion = false; }
|
|
548
|
-
if (!isUpdateRegion)
|
|
549
|
-
needUpdate = true;
|
|
550
|
-
var meshWorld = {
|
|
551
|
-
matrix: (_a = object3D.matrix) === null || _a === void 0 ? void 0 : _a.value()
|
|
552
|
-
};
|
|
553
|
-
var globalWorld = {
|
|
554
|
-
matrix: this.__scene.matrix.value(),
|
|
555
|
-
proporion: this.__proporion
|
|
556
|
-
};
|
|
557
|
-
this.setRegion(object3D.region);
|
|
558
|
-
for (var index = 0; index < object3D.mesh.length; index++) {
|
|
559
|
-
if (isUpdateRegion) {
|
|
560
|
-
if (this.__regionPainter) {
|
|
561
|
-
doDraw("painter" + this.__unique, this.__regionPainter, {
|
|
562
|
-
geometry: object3D.mesh[index].geometry,
|
|
563
|
-
material: {
|
|
564
|
-
color: {
|
|
565
|
-
r: this.__regionColor[0],
|
|
566
|
-
g: this.__regionColor[1],
|
|
567
|
-
b: this.__regionColor[2],
|
|
568
|
-
alpha: this.__regionColor[3]
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
}, meshWorld, globalWorld);
|
|
572
|
-
this.__getColor = getColorFactory(this.__regionPainter);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
else {
|
|
576
|
-
doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
WebGL.prototype.render = function (object3D) {
|
|
581
|
-
if (!('matrix' in object3D))
|
|
582
|
-
object3D.matrix = new Matrix4();
|
|
583
|
-
if (!('region' in object3D))
|
|
584
|
-
object3D.region = "";
|
|
585
|
-
for (var index = 0; index < object3D.mesh.length; index++) {
|
|
586
|
-
var mesh = object3D.mesh[index];
|
|
587
|
-
if (mesh.geometry.attributes.normal && Array.isArray(mesh.geometry.attributes.normal.array)) {
|
|
588
|
-
mesh.geometry.attributes.normal.array = new Float32Array(mesh.geometry.attributes.normal.array);
|
|
589
|
-
}
|
|
590
|
-
if (mesh.geometry.attributes.position && Array.isArray(mesh.geometry.attributes.position.array)) {
|
|
591
|
-
mesh.geometry.attributes.position.array = new Float32Array(mesh.geometry.attributes.position.array);
|
|
592
|
-
}
|
|
593
|
-
if (mesh.geometry.attributes.uv && Array.isArray(mesh.geometry.attributes.uv.array)) {
|
|
594
|
-
mesh.geometry.attributes.uv.array = new Float32Array(mesh.geometry.attributes.uv.array);
|
|
595
|
-
}
|
|
596
|
-
if (mesh.geometry.index && Array.isArray(mesh.geometry.index.array)) {
|
|
597
|
-
mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array);
|
|
598
|
-
}
|
|
599
|
-
if (mesh.material.colors && Array.isArray(mesh.material.colors.array)) {
|
|
600
|
-
mesh.material.colors.array = new Float32Array(mesh.material.colors.array);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
this.__scene.children.push(object3D);
|
|
604
|
-
this.draw(object3D);
|
|
605
|
-
};
|
|
606
|
-
WebGL.prototype.setRegion = function (regionName) {
|
|
607
|
-
this.__regionName = regionName + "";
|
|
608
|
-
if (regionName) {
|
|
609
|
-
if (this.__regionList[regionName] == void 0) {
|
|
610
|
-
this.__regionList[regionName] = __spreadArray(__spreadArray([], this.__regionAssemble(), true), [1], false);
|
|
611
|
-
}
|
|
612
|
-
this.__regionColor = this.__regionList[regionName];
|
|
613
|
-
}
|
|
614
|
-
else {
|
|
615
|
-
this.__regionColor = [0, 0, 0, 1];
|
|
616
|
-
}
|
|
617
|
-
return this;
|
|
618
|
-
};
|
|
619
|
-
WebGL.prototype.getRegion = function (x, y) {
|
|
620
|
-
var _this = this;
|
|
621
|
-
if (needUpdate)
|
|
622
|
-
this.review(true);
|
|
623
|
-
needUpdate = false;
|
|
624
|
-
return new Promise(function (resolve) {
|
|
625
|
-
var rgba = _this.__getColor(x, y);
|
|
626
|
-
for (var key in _this.__regionList) {
|
|
627
|
-
var currentRGBA = _this.__regionList[key];
|
|
628
|
-
if ("rgba(" + currentRGBA[0] * 255 + "," + currentRGBA[1] * 255 + "," + currentRGBA[2] * 255 + "," + currentRGBA[3] * 255 + ")" == rgba) {
|
|
629
|
-
resolve(key);
|
|
630
|
-
break;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
resolve("");
|
|
634
|
-
});
|
|
635
|
-
};
|
|
636
|
-
return WebGL;
|
|
478
|
+
var needUpdate = false;
|
|
479
|
+
var scale = 10;
|
|
480
|
+
var WebGL = (function () {
|
|
481
|
+
function WebGL(ViewCanvas, RegionCanvas, mode) {
|
|
482
|
+
this.name = "WebGL";
|
|
483
|
+
this.__getColor = function (x, y) { return "rgba(0,0,0,1)"; };
|
|
484
|
+
this.__regionList = {};
|
|
485
|
+
this.__regionAssemble = assemble(0, 1, 0.2, 3);
|
|
486
|
+
this.__regionName = "";
|
|
487
|
+
this.__regionColor = [0, 0, 0, 1];
|
|
488
|
+
this.__scene = {
|
|
489
|
+
children: [],
|
|
490
|
+
matrix: new Matrix4([
|
|
491
|
+
1, 0, 0, 0,
|
|
492
|
+
0, 1, 0, 0,
|
|
493
|
+
0, 0, 1, 0,
|
|
494
|
+
0, 0, 0, scale
|
|
495
|
+
])
|
|
496
|
+
};
|
|
497
|
+
this.__unique = new Date().valueOf();
|
|
498
|
+
this.painter = getWebGLContext(ViewCanvas, scale, {}, mode);
|
|
499
|
+
if (RegionCanvas) {
|
|
500
|
+
this.__regionPainter = getWebGLContext(RegionCanvas, scale, {}, mode);
|
|
501
|
+
}
|
|
502
|
+
var proportion = this.painter.canvas.width / this.painter.canvas.height;
|
|
503
|
+
var xProportion = 1;
|
|
504
|
+
var yProportion = 1;
|
|
505
|
+
if (proportion > 1) {
|
|
506
|
+
xProportion = 1 / proportion;
|
|
507
|
+
}
|
|
508
|
+
else {
|
|
509
|
+
yProportion = proportion;
|
|
510
|
+
}
|
|
511
|
+
var zProportion = Math.min(xProportion, yProportion);
|
|
512
|
+
this.__proporion = [
|
|
513
|
+
xProportion, 0, 0, 0,
|
|
514
|
+
0, yProportion, 0, 0,
|
|
515
|
+
0, 0, zProportion, 0,
|
|
516
|
+
0, 0, 0, 1
|
|
517
|
+
];
|
|
518
|
+
}
|
|
519
|
+
WebGL.prototype.matrix = function (initMatrix4) {
|
|
520
|
+
return new Matrix4(initMatrix4);
|
|
521
|
+
};
|
|
522
|
+
WebGL.prototype.getMatrix = function () {
|
|
523
|
+
return this.__scene.matrix;
|
|
524
|
+
};
|
|
525
|
+
WebGL.prototype.getObject3D = function () {
|
|
526
|
+
return this.__scene.children;
|
|
527
|
+
};
|
|
528
|
+
WebGL.prototype.review = function (isUpdateRegion) {
|
|
529
|
+
if (isUpdateRegion === void 0) { isUpdateRegion = false; }
|
|
530
|
+
if (isUpdateRegion) {
|
|
531
|
+
if (this.__regionPainter) {
|
|
532
|
+
this.__regionPainter.clearColor(1, 1, 1, 1);
|
|
533
|
+
this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
else {
|
|
537
|
+
this.painter.clearColor(1, 1, 1, 1);
|
|
538
|
+
this.painter.clear(this.painter.COLOR_BUFFER_BIT);
|
|
539
|
+
}
|
|
540
|
+
for (var index = 0; index < this.__scene.children.length; index++) {
|
|
541
|
+
this.draw(this.__scene.children[index], isUpdateRegion);
|
|
542
|
+
}
|
|
543
|
+
return this;
|
|
544
|
+
};
|
|
545
|
+
WebGL.prototype.draw = function (object3D, isUpdateRegion) {
|
|
546
|
+
var _a;
|
|
547
|
+
if (isUpdateRegion === void 0) { isUpdateRegion = false; }
|
|
548
|
+
if (!isUpdateRegion)
|
|
549
|
+
needUpdate = true;
|
|
550
|
+
var meshWorld = {
|
|
551
|
+
matrix: (_a = object3D.matrix) === null || _a === void 0 ? void 0 : _a.value()
|
|
552
|
+
};
|
|
553
|
+
var globalWorld = {
|
|
554
|
+
matrix: this.__scene.matrix.value(),
|
|
555
|
+
proporion: this.__proporion
|
|
556
|
+
};
|
|
557
|
+
this.setRegion(object3D.region);
|
|
558
|
+
for (var index = 0; index < object3D.mesh.length; index++) {
|
|
559
|
+
if (isUpdateRegion) {
|
|
560
|
+
if (this.__regionPainter) {
|
|
561
|
+
doDraw("painter" + this.__unique, this.__regionPainter, {
|
|
562
|
+
geometry: object3D.mesh[index].geometry,
|
|
563
|
+
material: {
|
|
564
|
+
color: {
|
|
565
|
+
r: this.__regionColor[0],
|
|
566
|
+
g: this.__regionColor[1],
|
|
567
|
+
b: this.__regionColor[2],
|
|
568
|
+
alpha: this.__regionColor[3]
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}, meshWorld, globalWorld);
|
|
572
|
+
this.__getColor = getColorFactory(this.__regionPainter);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
WebGL.prototype.render = function (object3D) {
|
|
581
|
+
if (!('matrix' in object3D))
|
|
582
|
+
object3D.matrix = new Matrix4();
|
|
583
|
+
if (!('region' in object3D))
|
|
584
|
+
object3D.region = "";
|
|
585
|
+
for (var index = 0; index < object3D.mesh.length; index++) {
|
|
586
|
+
var mesh = object3D.mesh[index];
|
|
587
|
+
if (mesh.geometry.attributes.normal && Array.isArray(mesh.geometry.attributes.normal.array)) {
|
|
588
|
+
mesh.geometry.attributes.normal.array = new Float32Array(mesh.geometry.attributes.normal.array);
|
|
589
|
+
}
|
|
590
|
+
if (mesh.geometry.attributes.position && Array.isArray(mesh.geometry.attributes.position.array)) {
|
|
591
|
+
mesh.geometry.attributes.position.array = new Float32Array(mesh.geometry.attributes.position.array);
|
|
592
|
+
}
|
|
593
|
+
if (mesh.geometry.attributes.uv && Array.isArray(mesh.geometry.attributes.uv.array)) {
|
|
594
|
+
mesh.geometry.attributes.uv.array = new Float32Array(mesh.geometry.attributes.uv.array);
|
|
595
|
+
}
|
|
596
|
+
if (mesh.geometry.index && Array.isArray(mesh.geometry.index.array)) {
|
|
597
|
+
mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array);
|
|
598
|
+
}
|
|
599
|
+
if (mesh.material.colors && Array.isArray(mesh.material.colors.array)) {
|
|
600
|
+
mesh.material.colors.array = new Float32Array(mesh.material.colors.array);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
this.__scene.children.push(object3D);
|
|
604
|
+
this.draw(object3D);
|
|
605
|
+
};
|
|
606
|
+
WebGL.prototype.setRegion = function (regionName) {
|
|
607
|
+
this.__regionName = regionName + "";
|
|
608
|
+
if (regionName) {
|
|
609
|
+
if (this.__regionList[regionName] == void 0) {
|
|
610
|
+
this.__regionList[regionName] = __spreadArray(__spreadArray([], this.__regionAssemble(), true), [1], false);
|
|
611
|
+
}
|
|
612
|
+
this.__regionColor = this.__regionList[regionName];
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
this.__regionColor = [0, 0, 0, 1];
|
|
616
|
+
}
|
|
617
|
+
return this;
|
|
618
|
+
};
|
|
619
|
+
WebGL.prototype.getRegion = function (x, y) {
|
|
620
|
+
var _this = this;
|
|
621
|
+
if (needUpdate)
|
|
622
|
+
this.review(true);
|
|
623
|
+
needUpdate = false;
|
|
624
|
+
return new Promise(function (resolve) {
|
|
625
|
+
var rgba = _this.__getColor(x, y);
|
|
626
|
+
for (var key in _this.__regionList) {
|
|
627
|
+
var currentRGBA = _this.__regionList[key];
|
|
628
|
+
if ("rgba(" + currentRGBA[0] * 255 + "," + currentRGBA[1] * 255 + "," + currentRGBA[2] * 255 + "," + currentRGBA[3] * 255 + ")" == rgba) {
|
|
629
|
+
resolve(key);
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
resolve("");
|
|
634
|
+
});
|
|
635
|
+
};
|
|
636
|
+
return WebGL;
|
|
637
637
|
}());
|
|
638
638
|
|
|
639
639
|
export { WebGL as default };
|