@antv/l7-renderer 2.21.0 → 2.21.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/es/device/DeviceAttribute.js +26 -32
- package/es/device/DeviceBuffer.js +31 -49
- package/es/device/DeviceCache.js +136 -170
- package/es/device/DeviceElements.js +32 -38
- package/es/device/DeviceFramebuffer.js +76 -104
- package/es/device/DeviceModel.js +358 -384
- package/es/device/DeviceTexture2D.js +103 -122
- package/es/device/constants.js +117 -34
- package/es/device/index.js +254 -381
- package/es/device/utils/HashMap.js +71 -138
- package/es/device/utils/pipeline.js +6 -1
- package/es/device/utils/typedarray.js +23 -24
- package/es/device/utils/webgl.js +7 -6
- package/es/index.js +5 -4
- package/es/regl/ReglAttribute.js +17 -33
- package/es/regl/ReglBuffer.js +25 -40
- package/es/regl/ReglElements.js +21 -36
- package/es/regl/ReglFramebuffer.js +24 -44
- package/es/regl/ReglModel.js +266 -306
- package/es/regl/ReglRenderbuffer.js +19 -36
- package/es/regl/ReglTexture2D.js +72 -103
- package/es/regl/constants.js +133 -21
- package/es/regl/index.js +205 -290
- package/lib/device/DeviceAttribute.d.ts +13 -0
- package/lib/device/DeviceBuffer.d.ts +18 -0
- package/lib/device/DeviceCache.d.ts +14 -0
- package/lib/device/DeviceElements.d.ts +13 -0
- package/lib/device/DeviceFramebuffer.d.ts +24 -0
- package/lib/device/DeviceModel.d.ts +53 -0
- package/lib/device/DeviceModel.js +22 -15
- package/lib/device/DeviceTexture2D.d.ts +23 -0
- package/lib/device/constants.d.ts +35 -0
- package/lib/device/index.d.ts +68 -0
- package/lib/device/index.js +58 -36
- package/lib/device/utils/HashMap.d.ts +24 -0
- package/lib/device/utils/pipeline.d.ts +1 -0
- package/lib/device/utils/typedarray.d.ts +7 -0
- package/lib/device/utils/webgl.d.ts +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/regl/ReglAttribute.d.ts +16 -0
- package/lib/regl/ReglBuffer.d.ts +17 -0
- package/lib/regl/ReglElements.d.ts +14 -0
- package/lib/regl/ReglFramebuffer.d.ts +16 -0
- package/lib/regl/ReglModel.d.ts +46 -0
- package/lib/regl/ReglModel.js +21 -11
- package/lib/regl/ReglRenderbuffer.d.ts +16 -0
- package/lib/regl/ReglTexture2D.d.ts +22 -0
- package/lib/regl/constants.d.ts +43 -0
- package/lib/regl/index.d.ts +56 -0
- package/lib/regl/index.js +70 -48
- package/package.json +14 -18
- package/CHANGELOG.md +0 -350
- package/LICENSE.md +0 -21
package/es/regl/ReglModel.js
CHANGED
|
@@ -1,366 +1,326 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
12
20
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
// src/regl/ReglModel.ts
|
|
22
|
+
import {
|
|
23
|
+
ClipSpaceNearZ,
|
|
24
|
+
preprocessShader_GLSL,
|
|
25
|
+
ViewportOrigin
|
|
26
|
+
} from "@antv/g-device-api";
|
|
27
|
+
import { gl, removeDuplicateUniforms } from "@antv/l7-core";
|
|
28
|
+
import { lodashUtil } from "@antv/l7-utils";
|
|
29
|
+
import {
|
|
30
|
+
blendEquationMap,
|
|
31
|
+
blendFuncMap,
|
|
32
|
+
cullFaceMap,
|
|
33
|
+
depthFuncMap,
|
|
34
|
+
primitiveMap,
|
|
35
|
+
stencilFuncMap,
|
|
36
|
+
stencilOpMap
|
|
37
|
+
} from "./constants";
|
|
38
|
+
var { isPlainObject, isTypedArray } = lodashUtil;
|
|
39
|
+
var ReglModel = class {
|
|
40
|
+
constructor(reGl, options) {
|
|
41
|
+
this.destroyed = false;
|
|
42
|
+
this.uniforms = {};
|
|
21
43
|
this.reGl = reGl;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
platformString: 'WebGL1',
|
|
38
|
-
glslVersion: '#version 100',
|
|
44
|
+
const {
|
|
45
|
+
vs,
|
|
46
|
+
fs,
|
|
47
|
+
attributes,
|
|
48
|
+
uniforms,
|
|
49
|
+
primitive,
|
|
50
|
+
count,
|
|
51
|
+
elements,
|
|
52
|
+
depth,
|
|
53
|
+
cull,
|
|
54
|
+
instances
|
|
55
|
+
} = options;
|
|
56
|
+
const vendorInfo = {
|
|
57
|
+
platformString: "WebGL1",
|
|
58
|
+
glslVersion: "#version 100",
|
|
39
59
|
explicitBindingLocations: false,
|
|
40
60
|
separateSamplerTextures: false,
|
|
41
61
|
viewportOrigin: ViewportOrigin.LOWER_LEFT,
|
|
42
62
|
clipSpaceNearZ: ClipSpaceNearZ.NEGATIVE_ONE,
|
|
43
63
|
supportMRT: false
|
|
44
64
|
};
|
|
45
|
-
|
|
65
|
+
const reglUniforms = {};
|
|
46
66
|
this.options = options;
|
|
47
67
|
if (uniforms) {
|
|
48
68
|
this.uniforms = this.extractUniforms(uniforms);
|
|
49
|
-
Object.keys(uniforms).forEach(
|
|
50
|
-
// use regl prop API
|
|
51
|
-
// @ts-ignore
|
|
69
|
+
Object.keys(uniforms).forEach((uniformName) => {
|
|
52
70
|
reglUniforms[uniformName] = reGl.prop(uniformName);
|
|
53
71
|
});
|
|
54
72
|
}
|
|
55
|
-
|
|
56
|
-
Object.keys(attributes).forEach(
|
|
73
|
+
const reglAttributes = {};
|
|
74
|
+
Object.keys(attributes).forEach((name) => {
|
|
57
75
|
reglAttributes[name] = attributes[name].get();
|
|
58
76
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
77
|
+
const frag = removeDuplicateUniforms(
|
|
78
|
+
preprocessShader_GLSL(vendorInfo, "frag", fs, null, false)
|
|
79
|
+
);
|
|
80
|
+
const vert = removeDuplicateUniforms(
|
|
81
|
+
preprocessShader_GLSL(vendorInfo, "vert", vs, null, false)
|
|
82
|
+
);
|
|
83
|
+
const drawParams = {
|
|
62
84
|
attributes: reglAttributes,
|
|
63
|
-
frag
|
|
85
|
+
frag,
|
|
64
86
|
uniforms: reglUniforms,
|
|
65
|
-
vert
|
|
87
|
+
vert,
|
|
66
88
|
// @ts-ignore
|
|
67
|
-
colorMask: reGl.prop(
|
|
89
|
+
colorMask: reGl.prop("colorMask"),
|
|
68
90
|
lineWidth: 1,
|
|
69
91
|
blend: {
|
|
70
92
|
// @ts-ignore
|
|
71
|
-
enable: reGl.prop(
|
|
93
|
+
enable: reGl.prop("blend.enable"),
|
|
72
94
|
// @ts-ignore
|
|
73
|
-
func: reGl.prop(
|
|
95
|
+
func: reGl.prop("blend.func"),
|
|
74
96
|
// @ts-ignore
|
|
75
|
-
equation: reGl.prop(
|
|
97
|
+
equation: reGl.prop("blend.equation"),
|
|
76
98
|
// @ts-ignore
|
|
77
|
-
color: reGl.prop(
|
|
99
|
+
color: reGl.prop("blend.color")
|
|
78
100
|
},
|
|
79
101
|
stencil: {
|
|
80
102
|
// @ts-ignore
|
|
81
|
-
enable: reGl.prop(
|
|
103
|
+
enable: reGl.prop("stencil.enable"),
|
|
82
104
|
// @ts-ignore
|
|
83
|
-
mask: reGl.prop(
|
|
105
|
+
mask: reGl.prop("stencil.mask"),
|
|
84
106
|
// @ts-ignore
|
|
85
|
-
func: reGl.prop(
|
|
107
|
+
func: reGl.prop("stencil.func"),
|
|
86
108
|
// @ts-ignore
|
|
87
|
-
opFront: reGl.prop(
|
|
109
|
+
opFront: reGl.prop("stencil.opFront"),
|
|
88
110
|
// @ts-ignore
|
|
89
|
-
opBack: reGl.prop(
|
|
111
|
+
opBack: reGl.prop("stencil.opBack")
|
|
90
112
|
},
|
|
91
|
-
primitive: primitiveMap[primitive ===
|
|
113
|
+
primitive: primitiveMap[primitive === void 0 ? gl.TRIANGLES : primitive]
|
|
92
114
|
};
|
|
93
115
|
if (instances) {
|
|
94
116
|
drawParams.instances = instances;
|
|
95
117
|
}
|
|
96
|
-
|
|
97
|
-
// Tip:
|
|
98
|
-
// elements 中可能包含 count,此时不应传入
|
|
99
|
-
// count 和 elements 相比、count 优先
|
|
100
118
|
if (count) {
|
|
101
119
|
drawParams.count = count;
|
|
102
120
|
} else if (elements) {
|
|
103
121
|
drawParams.elements = elements.get();
|
|
104
122
|
}
|
|
105
|
-
this.initDepthDrawParams({
|
|
106
|
-
|
|
107
|
-
}, drawParams);
|
|
108
|
-
// this.initBlendDrawParams({ blend }, drawParams);
|
|
109
|
-
// this.initStencilDrawParams({ stencil }, drawParams);
|
|
110
|
-
this.initCullDrawParams({
|
|
111
|
-
cull: cull
|
|
112
|
-
}, drawParams);
|
|
123
|
+
this.initDepthDrawParams({ depth }, drawParams);
|
|
124
|
+
this.initCullDrawParams({ cull }, drawParams);
|
|
113
125
|
this.drawCommand = reGl(drawParams);
|
|
114
126
|
this.drawParams = drawParams;
|
|
115
127
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
value: function addUniforms(uniforms) {
|
|
140
|
-
this.uniforms = _objectSpread(_objectSpread({}, this.uniforms), this.extractUniforms(uniforms));
|
|
128
|
+
updateAttributesAndElements(attributes, elements) {
|
|
129
|
+
const reglAttributes = {};
|
|
130
|
+
Object.keys(attributes).forEach((name) => {
|
|
131
|
+
reglAttributes[name] = attributes[name].get();
|
|
132
|
+
});
|
|
133
|
+
this.drawParams.attributes = reglAttributes;
|
|
134
|
+
this.drawParams.elements = elements.get();
|
|
135
|
+
this.drawCommand = this.reGl(this.drawParams);
|
|
136
|
+
}
|
|
137
|
+
updateAttributes(attributes) {
|
|
138
|
+
const reglAttributes = {};
|
|
139
|
+
Object.keys(attributes).forEach((name) => {
|
|
140
|
+
reglAttributes[name] = attributes[name].get();
|
|
141
|
+
});
|
|
142
|
+
this.drawParams.attributes = reglAttributes;
|
|
143
|
+
this.drawCommand = this.reGl(this.drawParams);
|
|
144
|
+
}
|
|
145
|
+
addUniforms(uniforms) {
|
|
146
|
+
this.uniforms = __spreadValues(__spreadValues({}, this.uniforms), this.extractUniforms(uniforms));
|
|
147
|
+
}
|
|
148
|
+
draw(options, pick) {
|
|
149
|
+
if (this.drawParams.attributes && Object.keys(this.drawParams.attributes).length === 0) {
|
|
150
|
+
return;
|
|
141
151
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
152
|
+
const uniforms = __spreadValues(__spreadValues({}, this.uniforms), this.extractUniforms(options.uniforms || {}));
|
|
153
|
+
const reglDrawProps = {};
|
|
154
|
+
Object.keys(uniforms).forEach((uniformName) => {
|
|
155
|
+
const type = typeof uniforms[uniformName];
|
|
156
|
+
if (type === "boolean" || type === "number" || Array.isArray(uniforms[uniformName]) || // @ts-ignore
|
|
157
|
+
uniforms[uniformName].BYTES_PER_ELEMENT) {
|
|
158
|
+
reglDrawProps[uniformName] = uniforms[uniformName];
|
|
159
|
+
} else {
|
|
160
|
+
reglDrawProps[uniformName] = uniforms[uniformName].get();
|
|
147
161
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
162
|
+
});
|
|
163
|
+
reglDrawProps.blend = pick ? this.getBlendDrawParams({
|
|
164
|
+
blend: { enable: false }
|
|
165
|
+
}) : this.getBlendDrawParams(options);
|
|
166
|
+
reglDrawProps.stencil = this.getStencilDrawParams(options);
|
|
167
|
+
reglDrawProps.colorMask = this.getColorMaskDrawParams(options, pick);
|
|
168
|
+
this.drawCommand(reglDrawProps);
|
|
169
|
+
}
|
|
170
|
+
destroy() {
|
|
171
|
+
var _a, _b;
|
|
172
|
+
(_b = (_a = this.drawParams) == null ? void 0 : _a.elements) == null ? void 0 : _b.destroy();
|
|
173
|
+
if (this.options.attributes) {
|
|
174
|
+
Object.values(this.options.attributes).forEach((attr) => {
|
|
175
|
+
attr == null ? void 0 : attr.destroy();
|
|
159
176
|
});
|
|
160
|
-
// 更新 blend
|
|
161
|
-
// @ts-ignore
|
|
162
|
-
reglDrawProps.blend = pick // picking 操作不应该使用 blend
|
|
163
|
-
? this.getBlendDrawParams({
|
|
164
|
-
blend: {
|
|
165
|
-
enable: false
|
|
166
|
-
}
|
|
167
|
-
}) : this.getBlendDrawParams(options);
|
|
168
|
-
|
|
169
|
-
// 更新stentil 配置
|
|
170
|
-
// @ts-ignore
|
|
171
|
-
reglDrawProps.stencil = this.getStencilDrawParams(options);
|
|
172
|
-
// @ts-ignore
|
|
173
|
-
reglDrawProps.colorMask = this.getColorMaskDrawParams(options, pick);
|
|
174
|
-
|
|
175
|
-
// 在进行拾取操作的绘制中,不应该使用叠加模式 - picking 根据拾取的颜色作为判断的输入,而叠加模式会产生新的,在 id 序列中不存在的颜色
|
|
176
|
-
this.drawCommand(reglDrawProps);
|
|
177
|
-
}
|
|
178
|
-
}, {
|
|
179
|
-
key: "destroy",
|
|
180
|
-
value: function destroy() {
|
|
181
|
-
var _this$drawParams;
|
|
182
|
-
// @ts-ignore
|
|
183
|
-
(_this$drawParams = this.drawParams) === null || _this$drawParams === void 0 || (_this$drawParams = _this$drawParams.elements) === null || _this$drawParams === void 0 || _this$drawParams.destroy();
|
|
184
|
-
if (this.options.attributes) {
|
|
185
|
-
Object.values(this.options.attributes).forEach(function (attr) {
|
|
186
|
-
// @ts-ignore
|
|
187
|
-
attr === null || attr === void 0 || attr.destroy();
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
this.destroyed = true;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#depth-buffer
|
|
195
|
-
*/
|
|
196
|
-
}, {
|
|
197
|
-
key: "initDepthDrawParams",
|
|
198
|
-
value: function initDepthDrawParams(_ref, drawParams) {
|
|
199
|
-
var depth = _ref.depth;
|
|
200
|
-
if (depth) {
|
|
201
|
-
drawParams.depth = {
|
|
202
|
-
enable: depth.enable === undefined ? true : !!depth.enable,
|
|
203
|
-
mask: depth.mask === undefined ? true : !!depth.mask,
|
|
204
|
-
func: depthFuncMap[depth.func || gl.LESS],
|
|
205
|
-
range: depth.range || [0, 1]
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
177
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
enable: !!enable,
|
|
222
|
-
func: {
|
|
223
|
-
srcRGB: blendFuncMap[func && func.srcRGB || gl.SRC_ALPHA],
|
|
224
|
-
srcAlpha: blendFuncMap[func && func.srcAlpha || gl.SRC_ALPHA],
|
|
225
|
-
dstRGB: blendFuncMap[func && func.dstRGB || gl.ONE_MINUS_SRC_ALPHA],
|
|
226
|
-
dstAlpha: blendFuncMap[func && func.dstAlpha || gl.ONE_MINUS_SRC_ALPHA]
|
|
227
|
-
},
|
|
228
|
-
equation: {
|
|
229
|
-
rgb: blendEquationMap[equation && equation.rgb || gl.FUNC_ADD],
|
|
230
|
-
alpha: blendEquationMap[equation && equation.alpha || gl.FUNC_ADD]
|
|
231
|
-
},
|
|
232
|
-
color: color
|
|
178
|
+
this.destroyed = true;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#depth-buffer
|
|
182
|
+
*/
|
|
183
|
+
initDepthDrawParams({ depth }, drawParams) {
|
|
184
|
+
if (depth) {
|
|
185
|
+
drawParams.depth = {
|
|
186
|
+
enable: depth.enable === void 0 ? true : !!depth.enable,
|
|
187
|
+
mask: depth.mask === void 0 ? true : !!depth.mask,
|
|
188
|
+
func: depthFuncMap[depth.func || gl.LESS],
|
|
189
|
+
range: depth.range || [0, 1]
|
|
233
190
|
};
|
|
234
191
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
192
|
+
}
|
|
193
|
+
getBlendDrawParams({
|
|
194
|
+
blend
|
|
195
|
+
}) {
|
|
196
|
+
const { enable, func, equation, color = [0, 0, 0, 0] } = blend || {};
|
|
197
|
+
return {
|
|
198
|
+
enable: !!enable,
|
|
199
|
+
func: {
|
|
200
|
+
srcRGB: blendFuncMap[func && func.srcRGB || gl.SRC_ALPHA],
|
|
201
|
+
srcAlpha: blendFuncMap[func && func.srcAlpha || gl.SRC_ALPHA],
|
|
202
|
+
dstRGB: blendFuncMap[func && func.dstRGB || gl.ONE_MINUS_SRC_ALPHA],
|
|
203
|
+
dstAlpha: blendFuncMap[func && func.dstAlpha || gl.ONE_MINUS_SRC_ALPHA]
|
|
204
|
+
},
|
|
205
|
+
equation: {
|
|
206
|
+
rgb: blendEquationMap[equation && equation.rgb || gl.FUNC_ADD],
|
|
207
|
+
alpha: blendEquationMap[equation && equation.alpha || gl.FUNC_ADD]
|
|
208
|
+
},
|
|
209
|
+
color
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#stencil
|
|
214
|
+
*/
|
|
215
|
+
getStencilDrawParams({
|
|
216
|
+
stencil
|
|
217
|
+
}) {
|
|
218
|
+
const {
|
|
219
|
+
enable,
|
|
220
|
+
mask = -1,
|
|
221
|
+
func = {
|
|
222
|
+
cmp: gl.ALWAYS,
|
|
223
|
+
ref: 0,
|
|
224
|
+
mask: -1
|
|
225
|
+
},
|
|
226
|
+
opFront = {
|
|
227
|
+
fail: gl.KEEP,
|
|
228
|
+
zfail: gl.KEEP,
|
|
229
|
+
zpass: gl.KEEP
|
|
230
|
+
},
|
|
231
|
+
opBack = {
|
|
232
|
+
fail: gl.KEEP,
|
|
233
|
+
zfail: gl.KEEP,
|
|
234
|
+
zpass: gl.KEEP
|
|
235
|
+
}
|
|
236
|
+
} = stencil || {};
|
|
237
|
+
return {
|
|
238
|
+
enable: !!enable,
|
|
239
|
+
mask,
|
|
240
|
+
func: __spreadProps(__spreadValues({}, func), {
|
|
241
|
+
cmp: stencilFuncMap[func.cmp]
|
|
242
|
+
}),
|
|
243
|
+
opFront: {
|
|
244
|
+
fail: stencilOpMap[opFront.fail],
|
|
245
|
+
zfail: stencilOpMap[opFront.zfail],
|
|
246
|
+
zpass: stencilOpMap[opFront.zpass]
|
|
247
|
+
},
|
|
248
|
+
opBack: {
|
|
249
|
+
fail: stencilOpMap[opBack.fail],
|
|
250
|
+
zfail: stencilOpMap[opBack.zfail],
|
|
251
|
+
zpass: stencilOpMap[opBack.zpass]
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
getColorMaskDrawParams({ stencil }, pick) {
|
|
256
|
+
const colorMask = (stencil == null ? void 0 : stencil.enable) && stencil.opFront && !pick ? [false, false, false, false] : [true, true, true, true];
|
|
257
|
+
return colorMask;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#culling
|
|
261
|
+
*/
|
|
262
|
+
initCullDrawParams({ cull }, drawParams) {
|
|
263
|
+
if (cull) {
|
|
264
|
+
const { enable, face = gl.BACK } = cull;
|
|
265
|
+
drawParams.cull = {
|
|
265
266
|
enable: !!enable,
|
|
266
|
-
|
|
267
|
-
func: _objectSpread(_objectSpread({}, func), {}, {
|
|
268
|
-
cmp: stencilFuncMap[func.cmp]
|
|
269
|
-
}),
|
|
270
|
-
opFront: {
|
|
271
|
-
fail: stencilOpMap[opFront.fail],
|
|
272
|
-
zfail: stencilOpMap[opFront.zfail],
|
|
273
|
-
zpass: stencilOpMap[opFront.zpass]
|
|
274
|
-
},
|
|
275
|
-
opBack: {
|
|
276
|
-
fail: stencilOpMap[opBack.fail],
|
|
277
|
-
zfail: stencilOpMap[opBack.zfail],
|
|
278
|
-
zpass: stencilOpMap[opBack.zpass]
|
|
279
|
-
}
|
|
267
|
+
face: cullFaceMap[face]
|
|
280
268
|
};
|
|
281
269
|
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* 考虑结构体命名, eg:
|
|
273
|
+
* a: { b: 1 } -> 'a.b'
|
|
274
|
+
* a: [ { b: 1 } ] -> 'a[0].b'
|
|
275
|
+
*/
|
|
276
|
+
extractUniforms(uniforms) {
|
|
277
|
+
const extractedUniforms = {};
|
|
278
|
+
Object.keys(uniforms).forEach((uniformName) => {
|
|
279
|
+
this.extractUniformsRecursively(
|
|
280
|
+
uniformName,
|
|
281
|
+
uniforms[uniformName],
|
|
282
|
+
extractedUniforms,
|
|
283
|
+
""
|
|
284
|
+
);
|
|
285
|
+
});
|
|
286
|
+
return extractedUniforms;
|
|
287
|
+
}
|
|
288
|
+
extractUniformsRecursively(uniformName, uniformValue, uniforms, prefix) {
|
|
289
|
+
if (uniformValue === null || typeof uniformValue === "number" || // u_A: 1
|
|
290
|
+
typeof uniformValue === "boolean" || // u_A: false
|
|
291
|
+
Array.isArray(uniformValue) && typeof uniformValue[0] === "number" || // u_A: [1, 2, 3]
|
|
292
|
+
isTypedArray(uniformValue) || // u_A: Float32Array
|
|
293
|
+
// @ts-ignore
|
|
294
|
+
uniformValue === "" || "resize" in uniformValue) {
|
|
295
|
+
uniforms[`${prefix && prefix + "."}${uniformName}`] = uniformValue;
|
|
296
|
+
return;
|
|
308
297
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
var _this = this;
|
|
319
|
-
var extractedUniforms = {};
|
|
320
|
-
Object.keys(uniforms).forEach(function (uniformName) {
|
|
321
|
-
_this.extractUniformsRecursively(uniformName, uniforms[uniformName], extractedUniforms, '');
|
|
298
|
+
if (isPlainObject(uniformValue)) {
|
|
299
|
+
Object.keys(uniformValue).forEach((childName) => {
|
|
300
|
+
this.extractUniformsRecursively(
|
|
301
|
+
childName,
|
|
302
|
+
// @ts-ignore
|
|
303
|
+
uniformValue[childName],
|
|
304
|
+
uniforms,
|
|
305
|
+
`${prefix && prefix + "."}${uniformName}`
|
|
306
|
+
);
|
|
322
307
|
});
|
|
323
|
-
return extractedUniforms;
|
|
324
308
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
// u_A: 1
|
|
331
|
-
typeof uniformValue === 'boolean' ||
|
|
332
|
-
// u_A: false
|
|
333
|
-
Array.isArray(uniformValue) && typeof uniformValue[0] === 'number' ||
|
|
334
|
-
// u_A: [1, 2, 3]
|
|
335
|
-
isTypedArray(uniformValue) ||
|
|
336
|
-
// u_A: Float32Array
|
|
337
|
-
// @ts-ignore
|
|
338
|
-
uniformValue === '' || 'resize' in uniformValue) {
|
|
339
|
-
uniforms["".concat(prefix && prefix + '.').concat(uniformName)] = uniformValue;
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// u_Struct.a.b.c
|
|
344
|
-
if (isPlainObject(uniformValue)) {
|
|
345
|
-
Object.keys(uniformValue).forEach(function (childName) {
|
|
346
|
-
_this2.extractUniformsRecursively(childName,
|
|
347
|
-
// @ts-ignore
|
|
348
|
-
uniformValue[childName], uniforms, "".concat(prefix && prefix + '.').concat(uniformName));
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// u_Struct[0].a
|
|
353
|
-
if (Array.isArray(uniformValue)) {
|
|
354
|
-
uniformValue.forEach(function (child, idx) {
|
|
355
|
-
Object.keys(child).forEach(function (childName) {
|
|
356
|
-
_this2.extractUniformsRecursively(childName,
|
|
309
|
+
if (Array.isArray(uniformValue)) {
|
|
310
|
+
uniformValue.forEach((child, idx) => {
|
|
311
|
+
Object.keys(child).forEach((childName) => {
|
|
312
|
+
this.extractUniformsRecursively(
|
|
313
|
+
childName,
|
|
357
314
|
// @ts-ignore
|
|
358
|
-
child[childName],
|
|
359
|
-
|
|
315
|
+
child[childName],
|
|
316
|
+
uniforms,
|
|
317
|
+
`${prefix && prefix + "."}${uniformName}[${idx}]`
|
|
318
|
+
);
|
|
360
319
|
});
|
|
361
|
-
}
|
|
320
|
+
});
|
|
362
321
|
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
export {
|
|
325
|
+
ReglModel as default
|
|
326
|
+
};
|