@galacean/engine-core 1.2.0-alpha.0 → 1.2.0-alpha.10

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.
@@ -60,347 +60,6 @@ function _inherits(subClass, superClass) {
60
60
  if (superClass) _set_prototype_of(subClass, superClass);
61
61
  }
62
62
 
63
- /**
64
- * Common utility methods for math operations.
65
- */ var MathUtil = /*#__PURE__*/ function() {
66
- function MathUtil() {}
67
- /**
68
- * Clamps the specified value.
69
- * @param v - The specified value
70
- * @param min - The min value
71
- * @param max - The max value
72
- * @returns The result of clamping a value between min and max
73
- */ MathUtil.clamp = function clamp(v, min, max) {
74
- return Math.max(min, Math.min(max, v));
75
- };
76
- /**
77
- * Checks if a and b are almost equals.
78
- * The absolute value of the difference between a and b is close to zero.
79
- * @param a - The left value to compare
80
- * @param b - The right value to compare
81
- * @returns True if a almost equal to b, false otherwise
82
- */ MathUtil.equals = function equals(a, b) {
83
- return Math.abs(a - b) <= MathUtil.zeroTolerance;
84
- };
85
- /**
86
- * Determines whether the specified v is pow2.
87
- * @param v - The specified v
88
- * @returns True if the specified v is pow2, false otherwise
89
- */ MathUtil.isPowerOf2 = function isPowerOf2(v) {
90
- return (v & v - 1) === 0;
91
- };
92
- /**
93
- * Modify the specified r from radian to degree.
94
- * @param r - The specified r
95
- * @returns The degree value
96
- */ MathUtil.radianToDegree = function radianToDegree(r) {
97
- return r * MathUtil.radToDegreeFactor;
98
- };
99
- /**
100
- * Modify the specified d from degree to radian.
101
- * @param d - The specified d
102
- * @returns The radian value
103
- */ MathUtil.degreeToRadian = function degreeToRadian(d) {
104
- return d * MathUtil.degreeToRadFactor;
105
- };
106
- return MathUtil;
107
- }();
108
- (function() {
109
- /** The value for which all absolute numbers smaller than are considered equal to zero. */ MathUtil.zeroTolerance = 1e-6;
110
- })();
111
- (function() {
112
- /** The conversion factor that radian to degree. */ MathUtil.radToDegreeFactor = 180 / Math.PI;
113
- })();
114
- (function() {
115
- /** The conversion factor that degree to radian. */ MathUtil.degreeToRadFactor = Math.PI / 180;
116
- })();
117
-
118
- /**
119
- * Describes a color in the from of RGBA (in order: R, G, B, A).
120
- */ var Color = /*#__PURE__*/ function() {
121
- function Color(r, g, b, a) {
122
- if (r === void 0) r = 1;
123
- if (g === void 0) g = 1;
124
- if (b === void 0) b = 1;
125
- if (a === void 0) a = 1;
126
- /** @internal */ this._onValueChanged = null;
127
- this._r = r;
128
- this._g = g;
129
- this._b = b;
130
- this._a = a;
131
- }
132
- var _proto = Color.prototype;
133
- /**
134
- * Set the value of this color.
135
- * @param r - The red component of the color
136
- * @param g - The green component of the color
137
- * @param b - The blue component of the color
138
- * @param a - The alpha component of the color
139
- * @returns This color.
140
- */ _proto.set = function set(r, g, b, a) {
141
- this._r = r;
142
- this._g = g;
143
- this._b = b;
144
- this._a = a;
145
- this._onValueChanged && this._onValueChanged();
146
- return this;
147
- };
148
- /**
149
- * Determines the sum of this color and the specified color.
150
- * @param color - The specified color
151
- * @returns The added color
152
- */ _proto.add = function add(color) {
153
- this._r += color._r;
154
- this._g += color._g;
155
- this._b += color._b;
156
- this._a += color._a;
157
- this._onValueChanged && this._onValueChanged();
158
- return this;
159
- };
160
- /**
161
- * Scale this color by the given value.
162
- * @param s - The amount by which to scale the color
163
- * @returns The scaled color
164
- */ _proto.scale = function scale(s) {
165
- this._r *= s;
166
- this._g *= s;
167
- this._b *= s;
168
- this._a *= s;
169
- this._onValueChanged && this._onValueChanged();
170
- return this;
171
- };
172
- /**
173
- * Creates a clone of this color.
174
- * @returns A clone of this color
175
- */ _proto.clone = function clone() {
176
- var ret = new Color(this._r, this._g, this._b, this._a);
177
- return ret;
178
- };
179
- /**
180
- * Copy from color like object.
181
- * @param source - Color like object.
182
- * @returns This vector
183
- */ _proto.copyFrom = function copyFrom(source) {
184
- this._r = source.r;
185
- this._g = source.g;
186
- this._b = source.b;
187
- this._a = source.a;
188
- this._onValueChanged && this._onValueChanged();
189
- return this;
190
- };
191
- /**
192
- * Copy from array like object.
193
- * @param source - Array like object
194
- * @param offset - The start offset
195
- * @returns This color
196
- */ _proto.copyFromArray = function copyFromArray(source, offset) {
197
- if (offset === void 0) offset = 0;
198
- this._r = source[offset];
199
- this._g = source[offset + 1];
200
- this._b = source[offset + 2];
201
- this._a = source[offset + 3];
202
- this._onValueChanged && this._onValueChanged();
203
- return this;
204
- };
205
- /**
206
- * Copy the value of this color to an array.
207
- * @param out - The color
208
- * @param outOffset - The start offset
209
- */ _proto.copyToArray = function copyToArray(out, outOffset) {
210
- if (outOffset === void 0) outOffset = 0;
211
- out[outOffset] = this._r;
212
- out[outOffset + 1] = this._g;
213
- out[outOffset + 2] = this._b;
214
- out[outOffset + 3] = this._a;
215
- };
216
- /**
217
- * Modify components (r, g, b) of this color from gamma space to linear space.
218
- * @param out - The color in linear space
219
- * @returns The color in linear space
220
- */ _proto.toLinear = function toLinear(out) {
221
- out._r = Color.gammaToLinearSpace(this._r);
222
- out._g = Color.gammaToLinearSpace(this._g);
223
- out._b = Color.gammaToLinearSpace(this._b);
224
- this._onValueChanged && this._onValueChanged();
225
- return out;
226
- };
227
- /**
228
- * Modify components (r, g, b) of this color from linear space to gamma space.
229
- * @param out - The color in gamma space
230
- * @returns The color in gamma space
231
- */ _proto.toGamma = function toGamma(out) {
232
- out._r = Color.linearToGammaSpace(this._r);
233
- out._g = Color.linearToGammaSpace(this._g);
234
- out._b = Color.linearToGammaSpace(this._b);
235
- this._onValueChanged && this._onValueChanged();
236
- return out;
237
- };
238
- /**
239
- * Gets the brightness.
240
- * @returns The Hue-Saturation-Brightness (HSB) saturation for this
241
- */ _proto.getBrightness = function getBrightness() {
242
- var r = this.r;
243
- var g = this.g;
244
- var b = this.b;
245
- var max = r;
246
- var min = r;
247
- if (g > max) max = g;
248
- if (b > max) max = b;
249
- if (g < min) min = g;
250
- if (b < min) min = b;
251
- return (max + min) / 2;
252
- };
253
- /**
254
- * Serialize this color to a JSON representation.
255
- * @return A JSON representation of this color
256
- */ _proto.toJSON = function toJSON() {
257
- return {
258
- r: this._r,
259
- g: this._g,
260
- b: this._b,
261
- a: this._a
262
- };
263
- };
264
- /**
265
- * Modify a value from the gamma space to the linear space.
266
- * @param value - The value in gamma space
267
- * @returns The value in linear space
268
- */ Color.gammaToLinearSpace = function gammaToLinearSpace(value) {
269
- // https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_framebuffer_sRGB.txt
270
- // https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_texture_sRGB_decode.txt
271
- if (value <= 0.0) return 0.0;
272
- else if (value <= 0.04045) return value / 12.92;
273
- else if (value < 1.0) return Math.pow((value + 0.055) / 1.055, 2.4);
274
- else return Math.pow(value, 2.4);
275
- };
276
- /**
277
- * Modify a value from the linear space to the gamma space.
278
- * @param value - The value in linear space
279
- * @returns The value in gamma space
280
- */ Color.linearToGammaSpace = function linearToGammaSpace(value) {
281
- // https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_framebuffer_sRGB.txt
282
- // https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_texture_sRGB_decode.txt
283
- if (value <= 0.0) return 0.0;
284
- else if (value < 0.0031308) return 12.92 * value;
285
- else if (value < 1.0) return 1.055 * Math.pow(value, 0.41666) - 0.055;
286
- else return Math.pow(value, 0.41666);
287
- };
288
- /**
289
- * Determines whether the specified colors are equals.
290
- * @param left - The first color to compare
291
- * @param right - The second color to compare
292
- * @returns True if the specified colors are equals, false otherwise
293
- */ Color.equals = function equals(left, right) {
294
- return MathUtil.equals(left._r, right._r) && MathUtil.equals(left._g, right._g) && MathUtil.equals(left._b, right._b) && MathUtil.equals(left._a, right._a);
295
- };
296
- /**
297
- * Determines the sum of two colors.
298
- * @param left - The first color to add
299
- * @param right - The second color to add
300
- * @param out - The sum of two colors
301
- * @returns The added color
302
- */ Color.add = function add(left, right, out) {
303
- out._r = left._r + right._r;
304
- out._g = left._g + right._g;
305
- out._b = left._b + right._b;
306
- out._a = left._a + right._a;
307
- out._onValueChanged && out._onValueChanged();
308
- return out;
309
- };
310
- /**
311
- * Determines the difference between two colors.
312
- * @param left - The first color to subtract
313
- * @param right - The second color to subtract
314
- * @param out - The difference between two colors
315
- */ Color.subtract = function subtract(left, right, out) {
316
- out._r = left._r - right._r;
317
- out._g = left._g - right._g;
318
- out._b = left._b - right._b;
319
- out._a = left._a - right._a;
320
- out._onValueChanged && out._onValueChanged();
321
- };
322
- /**
323
- * Scale a color by the given value.
324
- * @param left - The color to scale
325
- * @param s - The amount by which to scale the color
326
- * @param out - The scaled color
327
- * @returns The scaled color
328
- */ Color.scale = function scale(left, s, out) {
329
- out._r = left._r * s;
330
- out._g = left._g * s;
331
- out._b = left._b * s;
332
- out._a = left._a * s;
333
- out._onValueChanged && out._onValueChanged();
334
- return out;
335
- };
336
- /**
337
- * Performs a linear interpolation between two color.
338
- * @param start - The first color
339
- * @param end - The second color
340
- * @param t - The blend amount where 0 returns start and 1 end
341
- * @param out - The result of linear blending between two color
342
- */ Color.lerp = function lerp(start, end, t, out) {
343
- var _r = start._r, _g = start._g, _b = start._b, _a = start._a;
344
- out._r = _r + (end._r - _r) * t;
345
- out._g = _g + (end._g - _g) * t;
346
- out._b = _b + (end._b - _b) * t;
347
- out._a = _a + (end._a - _a) * t;
348
- out._onValueChanged && out._onValueChanged();
349
- return out;
350
- };
351
- _create_class(Color, [
352
- {
353
- key: "r",
354
- get: /**
355
- * The red component of the color, 0~1.
356
- */ function get() {
357
- return this._r;
358
- },
359
- set: function set(value) {
360
- this._r = value;
361
- this._onValueChanged && this._onValueChanged();
362
- }
363
- },
364
- {
365
- key: "g",
366
- get: /**
367
- * The green component of the color, 0~1.
368
- */ function get() {
369
- return this._g;
370
- },
371
- set: function set(value) {
372
- this._g = value;
373
- this._onValueChanged && this._onValueChanged();
374
- }
375
- },
376
- {
377
- key: "b",
378
- get: /**
379
- * The blue component of the color, 0~1.
380
- */ function get() {
381
- return this._b;
382
- },
383
- set: function set(value) {
384
- this._b = value;
385
- this._onValueChanged && this._onValueChanged();
386
- }
387
- },
388
- {
389
- key: "a",
390
- get: /**
391
- * The alpha component of the color, 0~1.
392
- */ function get() {
393
- return this._a;
394
- },
395
- set: function set(value) {
396
- this._a = value;
397
- this._onValueChanged && this._onValueChanged();
398
- }
399
- }
400
- ]);
401
- return Color;
402
- }();
403
-
404
63
  /**
405
64
  * Sprite mask interaction.
406
65
  */ exports.SpriteMaskInteraction = void 0;
@@ -941,7 +600,14 @@ var Utils = /*#__PURE__*/ function() {
941
600
  * @param url - The url to be judged.
942
601
  * @returns Whether the url is absolute url.
943
602
  */ Utils.isAbsoluteUrl = function isAbsoluteUrl(url) {
944
- return /^(?:http|blob|data:|\/)/.test(url);
603
+ return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
604
+ };
605
+ /**
606
+ * Judge whether the url is base64 url.
607
+ * @param url - The url to be judged.
608
+ * @returns Whether the url is base64 url.
609
+ */ Utils.isBase64Url = function isBase64Url(url) {
610
+ return /^data:.*,.*$/i.test(url);
945
611
  };
946
612
  /**
947
613
  * Get the values of an object.
@@ -959,7 +625,10 @@ var Utils = /*#__PURE__*/ function() {
959
625
  if (Utils.isAbsoluteUrl(relativeUrl)) {
960
626
  return relativeUrl;
961
627
  }
962
- return baseUrl.substring(0, baseUrl.lastIndexOf("/") + 1) + this._formatRelativePath(relativeUrl);
628
+ if (Utils.isBase64Url(relativeUrl)) {
629
+ return relativeUrl;
630
+ }
631
+ return relativeUrl ? baseUrl.replace(/\/+$/, "") + "/" + relativeUrl.replace(/^\/+/, "") : baseUrl;
963
632
  };
964
633
  /**
965
634
  * @internal
@@ -2121,20 +1790,28 @@ var ActiveChangeFlag;
2121
1790
  this._enabled = value;
2122
1791
  if (this._entity._isActiveInScene) {
2123
1792
  if (value) {
2124
- this._phasedActiveInScene = true;
2125
- this._onEnableInScene();
1793
+ if (!this._phasedActiveInScene) {
1794
+ this._phasedActiveInScene = true;
1795
+ this._onEnableInScene();
1796
+ }
2126
1797
  } else {
2127
- this._phasedActiveInScene = false;
2128
- this._onDisableInScene();
1798
+ if (this._phasedActiveInScene) {
1799
+ this._phasedActiveInScene = false;
1800
+ this._onDisableInScene();
1801
+ }
2129
1802
  }
2130
1803
  }
2131
1804
  if (this._entity.isActiveInHierarchy) {
2132
1805
  if (value) {
2133
- this._phasedActive = true;
2134
- this._onEnable();
1806
+ if (!this._phasedActive) {
1807
+ this._phasedActive = true;
1808
+ this._onEnable();
1809
+ }
2135
1810
  } else {
2136
- this._phasedActive = false;
2137
- this._onDisable();
1811
+ if (this._phasedActive) {
1812
+ this._phasedActive = false;
1813
+ this._onDisable();
1814
+ }
2138
1815
  }
2139
1816
  }
2140
1817
  }
@@ -3507,7 +3184,7 @@ function _extends() {
3507
3184
  return _extends.apply(this, arguments);
3508
3185
  }
3509
3186
 
3510
- var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;"; // eslint-disable-line
3187
+ var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;uniform vec3 camera_Forward;"; // eslint-disable-line
3511
3188
 
3512
3189
  var common = "#define GLSLIFY 1\n#define PI 3.14159265359\n#define RECIPROCAL_PI 0.31830988618\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate( a ) clamp( a, 0.0, 1.0 )\nfloat pow2(float x){return x*x;}vec4 RGBMToLinear(vec4 value,float maxRange){return vec4(value.rgb*value.a*maxRange,1.0);}vec4 gammaToLinear(vec4 srgbIn){return vec4(pow(srgbIn.rgb,vec3(2.2)),srgbIn.a);}vec4 linearToGamma(vec4 linearIn){return vec4(pow(linearIn.rgb,vec3(1.0/2.2)),linearIn.a);}uniform vec4 camera_DepthBufferParams;float remapDepthBufferLinear01(float z){return 1.0/(camera_DepthBufferParams.x*z+camera_DepthBufferParams.y);}\n#ifdef GRAPHICS_API_WEBGL2\n#define INVERSE_MAT(mat) inverse(mat)\n#else\nmat2 inverseMat(mat2 m){return mat2(m[1][1],-m[0][1],-m[1][0],m[0][0])/(m[0][0]*m[1][1]-m[0][1]*m[1][0]);}mat3 inverseMat(mat3 m){float a00=m[0][0],a01=m[0][1],a02=m[0][2];float a10=m[1][0],a11=m[1][1],a12=m[1][2];float a20=m[2][0],a21=m[2][1],a22=m[2][2];float b01=a22*a11-a12*a21;float b11=-a22*a10+a12*a20;float b21=a21*a10-a11*a20;float det=a00*b01+a01*b11+a02*b21;return mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),b11,(a22*a00-a02*a20),(-a12*a00+a02*a10),b21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;}mat4 inverseMat(mat4 m){float a00=m[0][0],a01=m[0][1],a02=m[0][2],a03=m[0][3],a10=m[1][0],a11=m[1][1],a12=m[1][2],a13=m[1][3],a20=m[2][0],a21=m[2][1],a22=m[2][2],a23=m[2][3],a30=m[3][0],a31=m[3][1],a32=m[3][2],a33=m[3][3],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return mat4(a11*b11-a12*b10+a13*b09,a02*b10-a01*b11-a03*b09,a31*b05-a32*b04+a33*b03,a22*b04-a21*b05-a23*b03,a12*b08-a10*b11-a13*b07,a00*b11-a02*b08+a03*b07,a32*b02-a30*b05-a33*b01,a20*b05-a22*b02+a23*b01,a10*b10-a11*b08+a13*b06,a01*b08-a00*b10-a03*b06,a30*b04-a31*b02+a33*b00,a21*b02-a20*b04-a23*b00,a11*b07-a10*b09-a12*b06,a00*b09-a01*b07+a02*b06,a31*b01-a30*b03-a32*b00,a20*b03-a21*b01+a22*b00)/det;}\n#define INVERSE_MAT(mat) inverseMat(mat)\n#endif\n"; // eslint-disable-line
3513
3190
 
@@ -3557,7 +3234,7 @@ var mobile_material_frag = "#define GLSLIFY 1\nuniform vec4 material_EmissiveCol
3557
3234
 
3558
3235
  var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission=material_EmissiveColor;vec4 diffuse=material_BaseColor;vec4 specular=material_SpecularColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nvec4 emissiveTextureColor=texture2D(material_EmissiveTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nemissiveTextureColor=gammaToLinear(emissiveTextureColor);\n#endif\nemission*=emissiveTextureColor;\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 diffuseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ndiffuseTextureColor=gammaToLinear(diffuseTextureColor);\n#endif\ndiffuse*=diffuseTextureColor;\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\ndiffuse*=v_color;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\nvec4 specularTextureColor=texture2D(material_SpecularTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularTextureColor=gammaToLinear(specularTextureColor);\n#endif\nspecular*=specularTextureColor;\n#endif\nambient=vec4(scene_EnvMapLight.diffuse*scene_EnvMapLight.diffuseIntensity,1.0)*diffuse;"; // eslint-disable-line
3559
3236
 
3560
- var begin_viewdir_frag = "#define GLSLIFY 1\n#ifdef MATERIAL_NEED_WORLD_POS\nvec3 V=normalize(camera_Position-v_pos);\n#endif\n"; // eslint-disable-line
3237
+ var begin_viewdir_frag = "#define GLSLIFY 1\n#ifdef CAMERA_ORTHOGRAPHIC\nvec3 V=-camera_Forward;\n#else\n#ifdef MATERIAL_NEED_WORLD_POS\nvec3 V=normalize(camera_Position-v_pos);\n#endif\n#endif\n"; // eslint-disable-line
3561
3238
 
3562
3239
  var mobile_blinnphong_frag = "#define GLSLIFY 1\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nmat3 tbn=getTBN(gl_FrontFacing);vec3 N=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,gl_FrontFacing);\n#else\nvec3 N=getNormal(gl_FrontFacing);\n#endif\nvec3 lightDiffuse=vec3(0.0,0.0,0.0);vec3 lightSpecular=vec3(0.0,0.0,0.0);float shadowAttenuation=1.0;\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nshadowAttenuation=1.0;\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nshadowAttenuation*=sampleShadowMap();\n#endif\nDirectLight directionalLight;for(int i=0;i<SCENE_DIRECT_LIGHT_COUNT;i++){if(!isRendererCulledByLight(renderer_Layer.xy,scene_DirectLightCullingMask[i])){directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==0){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];float d=max(dot(N,-directionalLight.direction),0.0);lightDiffuse+=directionalLight.color*d;vec3 halfDir=normalize(V-directionalLight.direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess);lightSpecular+=directionalLight.color*s;}}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(!isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i])){pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];vec3 direction=v_pos-pointLight.position;float dist=length(direction);direction/=dist;float decay=clamp(1.0-pow(dist/pointLight.distance,4.0),0.0,1.0);float d=max(dot(N,-direction),0.0)*decay;lightDiffuse+=pointLight.color*d;vec3 halfDir=normalize(V-direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decay;lightSpecular+=pointLight.color*s;}}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nSpotLight spotLight;for(int i=0;i<SCENE_SPOT_LIGHT_COUNT;i++){if(!isRendererCulledByLight(renderer_Layer.xy,scene_SpotLightCullingMask[i])){spotLight.color=scene_SpotLightColor[i];spotLight.position=scene_SpotLightPosition[i];spotLight.direction=scene_SpotLightDirection[i];spotLight.distance=scene_SpotLightDistance[i];spotLight.angleCos=scene_SpotLightAngleCos[i];spotLight.penumbraCos=scene_SpotLightPenumbraCos[i];vec3 direction=spotLight.position-v_pos;float lightDistance=length(direction);direction/=lightDistance;float angleCos=dot(direction,-spotLight.direction);float decay=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayTotal=decay*spotEffect;float d=max(dot(N,direction),0.0)*decayTotal;lightDiffuse+=spotLight.color*d;vec3 halfDir=normalize(V+direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decayTotal;lightSpecular+=spotLight.color*s;}}\n#endif\ndiffuse*=vec4(lightDiffuse,1.0);specular*=vec4(lightSpecular,1.0);\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(diffuse.a<material_AlphaCutoff){discard;}\n#endif\n"; // eslint-disable-line
3563
3240
 
@@ -3595,7 +3272,7 @@ var noise_simplex_4D = "#define GLSLIFY 1\nvec4 grad4(float j,vec4 ip){const vec
3595
3272
 
3596
3273
  var pbr_frag_define = "#define GLSLIFY 1\n#define MIN_PERCEPTUAL_ROUGHNESS 0.045\n#define MIN_ROUGHNESS 0.002025\nuniform float material_AlphaCutoff;uniform vec4 material_BaseColor;uniform float material_Metal;uniform float material_Roughness;uniform float material_IOR;uniform vec3 material_PBRSpecularColor;uniform float material_Glossiness;uniform vec3 material_EmissiveColor;uniform float material_NormalIntensity;uniform float material_OcclusionIntensity;uniform float material_OcclusionTextureCoord;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nuniform float material_ClearCoat;uniform float material_ClearCoatRoughness;\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nuniform sampler2D material_ClearCoatTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nuniform sampler2D material_ClearCoatRoughnessTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\nuniform sampler2D material_ClearCoatNormalTexture;\n#endif\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nuniform vec3 material_AnisotropyInfo;\n#ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\nuniform sampler2D material_AnisotropyTexture;\n#endif\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nuniform sampler2D material_BaseTexture;\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nuniform sampler2D material_NormalTexture;\n#endif\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nuniform sampler2D material_EmissiveTexture;\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nuniform sampler2D material_RoughnessMetallicTexture;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nuniform sampler2D material_SpecularGlossinessTexture;\n#endif\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\nuniform sampler2D material_OcclusionTexture;\n#endif\nstruct ReflectedLight{vec3 directDiffuse;vec3 directSpecular;vec3 indirectDiffuse;vec3 indirectSpecular;};struct Geometry{vec3 position;vec3 normal;vec3 viewDir;float dotNV;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nvec3 clearCoatNormal;float clearCoatDotNV;\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 anisotropicT;vec3 anisotropicB;vec3 anisotropicN;float anisotropy;\n#endif\n};struct Material{vec3 diffuseColor;float roughness;vec3 specularColor;float opacity;float f0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoat;float clearCoatRoughness;\n#endif\n};"; // eslint-disable-line
3597
3274
 
3598
- var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecularOcclusion(float ambientOcclusion,float roughness,float dotNV){return saturate(pow(dotNV+ambientOcclusion,exp2(-16.0*roughness-1.0))-1.0+ambientOcclusion);}float getAARoughnessFactor(vec3 normal){\n#ifdef HAS_DERIVATIVES\nvec3 dxy=max(abs(dFdx(normal)),abs(dFdy(normal)));return MIN_PERCEPTUAL_ROUGHNESS+max(max(dxy.x,dxy.y),dxy.z);\n#else\nreturn MIN_PERCEPTUAL_ROUGHNESS;\n#endif\n}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 getAnisotropicBentNormal(Geometry geometry,vec3 n,float roughness){vec3 anisotropyDirection=geometry.anisotropy>=0.0 ? geometry.anisotropicB : geometry.anisotropicT;vec3 anisotropicTangent=cross(anisotropyDirection,geometry.viewDir);vec3 anisotropicNormal=cross(anisotropicTangent,anisotropyDirection);vec3 bentNormal=normalize(mix(n,anisotropicNormal,abs(geometry.anisotropy)*saturate(5.0*roughness)));return bentNormal;}\n#endif\nvoid initGeometry(out Geometry geometry,bool isFrontFacing){geometry.position=v_pos;geometry.viewDir=normalize(camera_Position-v_pos);\n#if defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY)\nmat3 tbn=getTBN(isFrontFacing);\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\ngeometry.normal=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.normal=getNormal(isFrontFacing);\n#endif\ngeometry.dotNV=saturate(dot(geometry.normal,geometry.viewDir));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\ngeometry.clearCoatNormal=getNormalByNormalTexture(tbn,material_ClearCoatNormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.clearCoatNormal=getNormal(isFrontFacing);\n#endif\ngeometry.clearCoatDotNV=saturate(dot(geometry.clearCoatNormal,geometry.viewDir));\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat anisotropy=material_AnisotropyInfo.z;vec3 anisotropicDirection=vec3(material_AnisotropyInfo.xy,0.0);\n#ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\nvec3 anisotropyTextureInfo=texture2D(material_AnisotropyTexture,v_uv).rgb;anisotropy*=anisotropyTextureInfo.b;anisotropicDirection.xy*=anisotropyTextureInfo.rg*2.0-1.0;\n#endif\ngeometry.anisotropy=anisotropy;geometry.anisotropicT=normalize(tbn*anisotropicDirection);geometry.anisotropicB=normalize(cross(geometry.normal,geometry.anisotropicT));\n#endif\n}void initMaterial(out Material material,inout Geometry geometry){vec4 baseColor=material_BaseColor;float metal=material_Metal;float roughness=material_Roughness;vec3 specularColor=material_PBRSpecularColor;float glossiness=material_Glossiness;float alphaCutoff=material_AlphaCutoff;float f0=pow2((material_IOR-1.0)/(material_IOR+1.0));material.f0=f0;\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 baseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nbaseTextureColor=gammaToLinear(baseTextureColor);\n#endif\nbaseColor*=baseTextureColor;\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nbaseColor*=v_color;\n#endif\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(baseColor.a<alphaCutoff){discard;}\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nvec4 metalRoughMapColor=texture2D(material_RoughnessMetallicTexture,v_uv);roughness*=metalRoughMapColor.g;metal*=metalRoughMapColor.b;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nvec4 specularGlossinessColor=texture2D(material_SpecularGlossinessTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularGlossinessColor=gammaToLinear(specularGlossinessColor);\n#endif\nspecularColor*=specularGlossinessColor.rgb;glossiness*=specularGlossinessColor.a;\n#endif\n#ifdef IS_METALLIC_WORKFLOW\nmaterial.diffuseColor=baseColor.rgb*(1.0-metal);material.specularColor=mix(vec3(f0),baseColor.rgb,metal);material.roughness=roughness;\n#else\nfloat specularStrength=max(max(specularColor.r,specularColor.g),specularColor.b);material.diffuseColor=baseColor.rgb*(1.0-specularStrength);material.specularColor=specularColor;material.roughness=1.0-glossiness;\n#endif\nmaterial.roughness=max(material.roughness,getAARoughnessFactor(geometry.normal));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nmaterial.clearCoat=material_ClearCoat;material.clearCoatRoughness=material_ClearCoatRoughness;\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nmaterial.clearCoat*=texture2D(material_ClearCoatTexture,v_uv).r;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nmaterial.clearCoatRoughness*=texture2D(material_ClearCoatRoughnessTexture,v_uv).g;\n#endif\nmaterial.clearCoat=saturate(material.clearCoat);material.clearCoatRoughness=max(material.clearCoatRoughness,getAARoughnessFactor(geometry.clearCoatNormal));\n#endif\n#ifdef MATERIAL_IS_TRANSPARENT\nmaterial.opacity=baseColor.a;\n#else\nmaterial.opacity=1.0;\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\ngeometry.anisotropicN=getAnisotropicBentNormal(geometry,geometry.normal,material.roughness);\n#endif\n}\n#include <brdf>\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n"; // eslint-disable-line
3275
+ var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecularOcclusion(float ambientOcclusion,float roughness,float dotNV){return saturate(pow(dotNV+ambientOcclusion,exp2(-16.0*roughness-1.0))-1.0+ambientOcclusion);}float getAARoughnessFactor(vec3 normal){\n#ifdef HAS_DERIVATIVES\nvec3 dxy=max(abs(dFdx(normal)),abs(dFdy(normal)));return MIN_PERCEPTUAL_ROUGHNESS+max(max(dxy.x,dxy.y),dxy.z);\n#else\nreturn MIN_PERCEPTUAL_ROUGHNESS;\n#endif\n}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 getAnisotropicBentNormal(Geometry geometry,vec3 n,float roughness){vec3 anisotropyDirection=geometry.anisotropy>=0.0 ? geometry.anisotropicB : geometry.anisotropicT;vec3 anisotropicTangent=cross(anisotropyDirection,geometry.viewDir);vec3 anisotropicNormal=cross(anisotropicTangent,anisotropyDirection);vec3 bentNormal=normalize(mix(n,anisotropicNormal,abs(geometry.anisotropy)*saturate(5.0*roughness)));return bentNormal;}\n#endif\nvoid initGeometry(out Geometry geometry,bool isFrontFacing){geometry.position=v_pos;\n#ifdef CAMERA_ORTHOGRAPHIC\ngeometry.viewDir=-camera_Forward;\n#else\ngeometry.viewDir=normalize(camera_Position-v_pos);\n#endif\n#if defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY)\nmat3 tbn=getTBN(isFrontFacing);\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\ngeometry.normal=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.normal=getNormal(isFrontFacing);\n#endif\ngeometry.dotNV=saturate(dot(geometry.normal,geometry.viewDir));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\ngeometry.clearCoatNormal=getNormalByNormalTexture(tbn,material_ClearCoatNormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.clearCoatNormal=getNormal(isFrontFacing);\n#endif\ngeometry.clearCoatDotNV=saturate(dot(geometry.clearCoatNormal,geometry.viewDir));\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat anisotropy=material_AnisotropyInfo.z;vec3 anisotropicDirection=vec3(material_AnisotropyInfo.xy,0.0);\n#ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\nvec3 anisotropyTextureInfo=texture2D(material_AnisotropyTexture,v_uv).rgb;anisotropy*=anisotropyTextureInfo.b;anisotropicDirection.xy*=anisotropyTextureInfo.rg*2.0-1.0;\n#endif\ngeometry.anisotropy=anisotropy;geometry.anisotropicT=normalize(tbn*anisotropicDirection);geometry.anisotropicB=normalize(cross(geometry.normal,geometry.anisotropicT));\n#endif\n}void initMaterial(out Material material,inout Geometry geometry){vec4 baseColor=material_BaseColor;float metal=material_Metal;float roughness=material_Roughness;vec3 specularColor=material_PBRSpecularColor;float glossiness=material_Glossiness;float alphaCutoff=material_AlphaCutoff;float f0=pow2((material_IOR-1.0)/(material_IOR+1.0));material.f0=f0;\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 baseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nbaseTextureColor=gammaToLinear(baseTextureColor);\n#endif\nbaseColor*=baseTextureColor;\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nbaseColor*=v_color;\n#endif\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(baseColor.a<alphaCutoff){discard;}\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nvec4 metalRoughMapColor=texture2D(material_RoughnessMetallicTexture,v_uv);roughness*=metalRoughMapColor.g;metal*=metalRoughMapColor.b;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nvec4 specularGlossinessColor=texture2D(material_SpecularGlossinessTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularGlossinessColor=gammaToLinear(specularGlossinessColor);\n#endif\nspecularColor*=specularGlossinessColor.rgb;glossiness*=specularGlossinessColor.a;\n#endif\n#ifdef IS_METALLIC_WORKFLOW\nmaterial.diffuseColor=baseColor.rgb*(1.0-metal);material.specularColor=mix(vec3(f0),baseColor.rgb,metal);material.roughness=roughness;\n#else\nfloat specularStrength=max(max(specularColor.r,specularColor.g),specularColor.b);material.diffuseColor=baseColor.rgb*(1.0-specularStrength);material.specularColor=specularColor;material.roughness=1.0-glossiness;\n#endif\nmaterial.roughness=max(material.roughness,getAARoughnessFactor(geometry.normal));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nmaterial.clearCoat=material_ClearCoat;material.clearCoatRoughness=material_ClearCoatRoughness;\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nmaterial.clearCoat*=texture2D(material_ClearCoatTexture,v_uv).r;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nmaterial.clearCoatRoughness*=texture2D(material_ClearCoatRoughnessTexture,v_uv).g;\n#endif\nmaterial.clearCoat=saturate(material.clearCoat);material.clearCoatRoughness=max(material.clearCoatRoughness,getAARoughnessFactor(geometry.clearCoatNormal));\n#endif\n#ifdef MATERIAL_IS_TRANSPARENT\nmaterial.opacity=baseColor.a;\n#else\nmaterial.opacity=1.0;\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\ngeometry.anisotropicN=getAnisotropicBentNormal(geometry,geometry.normal,material.roughness);\n#endif\n}\n#include <brdf>\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n"; // eslint-disable-line
3599
3276
 
3600
3277
  var brdf = "#define GLSLIFY 1\nfloat F_Schlick(float f0,float dotLH){return f0+0.96*(pow(1.0-dotLH,5.0));}vec3 F_Schlick(vec3 specularColor,float dotLH){float fresnel=exp2((-5.55473*dotLH-6.98316)*dotLH);return(1.0-specularColor)*fresnel+specularColor;}float G_GGX_SmithCorrelated(float alpha,float dotNL,float dotNV){float a2=pow2(alpha);float gv=dotNL*sqrt(a2+(1.0-a2)*pow2(dotNV));float gl=dotNV*sqrt(a2+(1.0-a2)*pow2(dotNL));return 0.5/max(gv+gl,EPSILON);}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat G_GGX_SmithCorrelated_Anisotropic(float at,float ab,float ToV,float BoV,float ToL,float BoL,float NoV,float NoL){float lambdaV=NoL*length(vec3(at*ToV,ab*BoV,NoV));float lambdaL=NoV*length(vec3(at*ToL,ab*BoL,NoL));return 0.5/max(lambdaV+lambdaL,EPSILON);}\n#endif\nfloat D_GGX(float alpha,float dotNH){float a2=pow2(alpha);float denom=pow2(dotNH)*(a2-1.0)+1.0;return RECIPROCAL_PI*a2/pow2(denom);}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat D_GGX_Anisotropic(float at,float ab,float ToH,float BoH,float NoH){float a2=at*ab;highp vec3 d=vec3(ab*ToH,at*BoH,a2*NoH);highp float d2=dot(d,d);float b2=a2/d2;return a2*b2*b2*RECIPROCAL_PI;}\n#endif\nvec3 isotropicLobe(vec3 specularColor,float alpha,float dotNV,float dotNL,float dotNH,float dotLH){vec3 F=F_Schlick(specularColor,dotLH);float D=D_GGX(alpha,dotNH);float G=G_GGX_SmithCorrelated(alpha,dotNL,dotNV);return F*(G*D);}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 anisotropicLobe(vec3 h,vec3 l,Geometry geometry,vec3 specularColor,float alpha,float dotNV,float dotNL,float dotNH,float dotLH){vec3 t=geometry.anisotropicT;vec3 b=geometry.anisotropicB;vec3 v=geometry.viewDir;float dotTV=dot(t,v);float dotBV=dot(b,v);float dotTL=dot(t,l);float dotBL=dot(b,l);float dotTH=dot(t,h);float dotBH=dot(b,h);float at=max(alpha*(1.0+geometry.anisotropy),MIN_ROUGHNESS);float ab=max(alpha*(1.0-geometry.anisotropy),MIN_ROUGHNESS);vec3 F=F_Schlick(specularColor,dotLH);float D=D_GGX_Anisotropic(at,ab,dotTH,dotBH,dotNH);float G=G_GGX_SmithCorrelated_Anisotropic(at,ab,dotTV,dotBV,dotTL,dotBL,dotNV,dotNL);return F*(G*D);}\n#endif\nvec3 BRDF_Specular_GGX(vec3 incidentDirection,Geometry geometry,vec3 normal,vec3 specularColor,float roughness){float alpha=pow2(roughness);vec3 halfDir=normalize(incidentDirection+geometry.viewDir);float dotNL=saturate(dot(normal,incidentDirection));float dotNV=saturate(dot(normal,geometry.viewDir));float dotNH=saturate(dot(normal,halfDir));float dotLH=saturate(dot(incidentDirection,halfDir));\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nreturn anisotropicLobe(halfDir,incidentDirection,geometry,specularColor,alpha,dotNV,dotNL,dotNH,dotLH);\n#else\nreturn isotropicLobe(specularColor,alpha,dotNV,dotNL,dotNH,dotLH);\n#endif\n}vec3 BRDF_Diffuse_Lambert(vec3 diffuseColor){return RECIPROCAL_PI*diffuseColor;}"; // eslint-disable-line
3601
3278
 
@@ -3616,7 +3293,7 @@ var PBRShaderLib = {
3616
3293
 
3617
3294
  var ShadowCoord = "#define GLSLIFY 1\nuniform mat4 scene_ShadowMatrices[SCENE_SHADOW_CASCADED_COUNT+1];uniform vec4 scene_ShadowSplitSpheres[4];mediump int computeCascadeIndex(vec3 positionWS){vec3 fromCenter0=positionWS-scene_ShadowSplitSpheres[0].xyz;vec3 fromCenter1=positionWS-scene_ShadowSplitSpheres[1].xyz;vec3 fromCenter2=positionWS-scene_ShadowSplitSpheres[2].xyz;vec3 fromCenter3=positionWS-scene_ShadowSplitSpheres[3].xyz;mediump vec4 comparison=vec4(dot(fromCenter0,fromCenter0)<scene_ShadowSplitSpheres[0].w,dot(fromCenter1,fromCenter1)<scene_ShadowSplitSpheres[1].w,dot(fromCenter2,fromCenter2)<scene_ShadowSplitSpheres[2].w,dot(fromCenter3,fromCenter3)<scene_ShadowSplitSpheres[3].w);comparison.yzw=clamp(comparison.yzw-comparison.xyz,0.0,1.0);mediump vec4 indexCoefficient=vec4(4.0,3.0,2.0,1.0);mediump int index=4-int(dot(comparison,indexCoefficient));return index;}vec3 getShadowCoord(){\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nmediump int cascadeIndex=0;\n#else\nmediump int cascadeIndex=computeCascadeIndex(v_pos);\n#endif\n#ifdef GRAPHICS_API_WEBGL2\nmat4 shadowMatrix=scene_ShadowMatrices[cascadeIndex];\n#else\nmat4 shadowMatrix;\n#if SCENE_SHADOW_CASCADED_COUNT == 4\nif(cascadeIndex==0){shadowMatrix=scene_ShadowMatrices[0];}else if(cascadeIndex==1){shadowMatrix=scene_ShadowMatrices[1];}else if(cascadeIndex==2){shadowMatrix=scene_ShadowMatrices[2];}else if(cascadeIndex==3){shadowMatrix=scene_ShadowMatrices[3];}else{shadowMatrix=scene_ShadowMatrices[4];}\n#endif\n#if SCENE_SHADOW_CASCADED_COUNT == 2\nif(cascadeIndex==0){shadowMatrix=scene_ShadowMatrices[0];}else if(cascadeIndex==1){shadowMatrix=scene_ShadowMatrices[1];}else{shadowMatrix=scene_ShadowMatrices[2];}\n#endif\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nif(cascadeIndex==0){shadowMatrix=scene_ShadowMatrices[0];}else{shadowMatrix=scene_ShadowMatrices[1];}\n#endif\n#endif\nvec4 shadowCoord=shadowMatrix*vec4(v_pos,1.0);return shadowCoord.xyz;}"; // eslint-disable-line
3618
3295
 
3619
- var ShadowFragmentDeclaration = "#define GLSLIFY 1\n#if defined(SCENE_SHADOW_TYPE) && defined(RENDERER_IS_RECEIVE_SHADOWS)\n#define SCENE_IS_CALCULATE_SHADOWS\n#endif\n#ifdef SCENE_IS_CALCULATE_SHADOWS\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nvarying vec3 v_shadowCoord;\n#else\n#include <ShadowCoord>\n#endif\nuniform vec3 scene_ShadowInfo;uniform vec4 scene_ShadowMapSize;\n#ifdef GRAPHICS_API_WEBGL2\nuniform mediump sampler2DShadow scene_ShadowMap;\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) textureLod(textureName, coord3 , 0.0)\n#define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2DShadow shadowMap\n#else\nuniform sampler2D scene_ShadowMap;\n#ifdef ENGINE_NO_DEPTH_TEXTURE\nconst vec4 bitShift=vec4(1.0,1.0/256.0,1.0/(256.0*256.0),1.0/(256.0*256.0*256.0));float unpack(const in vec4 rgbaDepth){return dot(rgbaDepth,bitShift);}\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) (unpack(texture2D(textureName, coord3.xy)) < coord3.z ? 0.0 : 1.0)\n#else\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) (texture2D(textureName, coord3.xy).r < coord3.z ? 0.0 : 1.0)\n#endif\n#define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2D shadowMap\n#endif\n#if SCENE_SHADOW_TYPE == 2\nfloat sampleShadowMapFiltered4(TEXTURE2D_SHADOW_PARAM(shadowMap),vec3 shadowCoord,vec4 shadowMapSize){float attenuation;vec4 attenuation4;vec2 offset=shadowMapSize.xy/2.0;vec3 shadowCoord0=shadowCoord+vec3(-offset,0.0);vec3 shadowCoord1=shadowCoord+vec3(offset.x,-offset.y,0.0);vec3 shadowCoord2=shadowCoord+vec3(-offset.x,offset.y,0.0);vec3 shadowCoord3=shadowCoord+vec3(offset,0.0);attenuation4.x=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord0);attenuation4.y=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord1);attenuation4.z=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord2);attenuation4.w=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord3);attenuation=dot(attenuation4,vec4(0.25));return attenuation;}\n#endif\n#if SCENE_SHADOW_TYPE == 3\n#include <shadow_sample_tent>\nfloat sampleShadowMapFiltered9(TEXTURE2D_SHADOW_PARAM(shadowMap),vec3 shadowCoord,vec4 shadowmapSize){float attenuation;float fetchesWeights[9];vec2 fetchesUV[9];sampleShadowComputeSamplesTent5x5(shadowmapSize,shadowCoord.xy,fetchesWeights,fetchesUV);attenuation=fetchesWeights[0]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[0].xy,shadowCoord.z));attenuation+=fetchesWeights[1]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[1].xy,shadowCoord.z));attenuation+=fetchesWeights[2]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[2].xy,shadowCoord.z));attenuation+=fetchesWeights[3]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[3].xy,shadowCoord.z));attenuation+=fetchesWeights[4]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[4].xy,shadowCoord.z));attenuation+=fetchesWeights[5]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[5].xy,shadowCoord.z));attenuation+=fetchesWeights[6]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[6].xy,shadowCoord.z));attenuation+=fetchesWeights[7]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[7].xy,shadowCoord.z));attenuation+=fetchesWeights[8]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[8].xy,shadowCoord.z));return attenuation;}\n#endif\nfloat sampleShadowMap(){\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nvec3 shadowCoord=v_shadowCoord;\n#else\nvec3 shadowCoord=getShadowCoord();\n#endif\nfloat attenuation=1.0;if(shadowCoord.z>0.0&&shadowCoord.z<1.0){\n#if SCENE_SHADOW_TYPE == 1\nattenuation=SAMPLE_TEXTURE2D_SHADOW(scene_ShadowMap,shadowCoord);\n#endif\n#if SCENE_SHADOW_TYPE == 2\nattenuation=sampleShadowMapFiltered4(scene_ShadowMap,shadowCoord,scene_ShadowMapSize);\n#endif\n#if SCENE_SHADOW_TYPE == 3\nattenuation=sampleShadowMapFiltered9(scene_ShadowMap,shadowCoord,scene_ShadowMapSize);\n#endif\nattenuation=mix(1.0,attenuation,scene_ShadowInfo.x);}return attenuation;}\n#endif\n"; // eslint-disable-line
3296
+ var ShadowFragmentDeclaration = "#define GLSLIFY 1\n#if defined(SCENE_SHADOW_TYPE) && defined(RENDERER_IS_RECEIVE_SHADOWS)\n#define SCENE_IS_CALCULATE_SHADOWS\n#endif\n#ifdef SCENE_IS_CALCULATE_SHADOWS\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nvarying vec3 v_shadowCoord;\n#else\n#include <ShadowCoord>\n#endif\nuniform vec4 scene_ShadowInfo;uniform vec4 scene_ShadowMapSize;\n#ifdef GRAPHICS_API_WEBGL2\nuniform mediump sampler2DShadow scene_ShadowMap;\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) textureLod(textureName, coord3 , 0.0)\n#define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2DShadow shadowMap\n#else\nuniform sampler2D scene_ShadowMap;\n#ifdef ENGINE_NO_DEPTH_TEXTURE\nconst vec4 bitShift=vec4(1.0,1.0/256.0,1.0/(256.0*256.0),1.0/(256.0*256.0*256.0));float unpack(const in vec4 rgbaDepth){return dot(rgbaDepth,bitShift);}\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) (unpack(texture2D(textureName, coord3.xy)) < coord3.z ? 0.0 : 1.0)\n#else\n#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) (texture2D(textureName, coord3.xy).r < coord3.z ? 0.0 : 1.0)\n#endif\n#define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2D shadowMap\n#endif\n#if SCENE_SHADOW_TYPE == 2\nfloat sampleShadowMapFiltered4(TEXTURE2D_SHADOW_PARAM(shadowMap),vec3 shadowCoord,vec4 shadowMapSize){float attenuation;vec4 attenuation4;vec2 offset=shadowMapSize.xy/2.0;vec3 shadowCoord0=shadowCoord+vec3(-offset,0.0);vec3 shadowCoord1=shadowCoord+vec3(offset.x,-offset.y,0.0);vec3 shadowCoord2=shadowCoord+vec3(-offset.x,offset.y,0.0);vec3 shadowCoord3=shadowCoord+vec3(offset,0.0);attenuation4.x=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord0);attenuation4.y=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord1);attenuation4.z=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord2);attenuation4.w=SAMPLE_TEXTURE2D_SHADOW(shadowMap,shadowCoord3);attenuation=dot(attenuation4,vec4(0.25));return attenuation;}\n#endif\n#if SCENE_SHADOW_TYPE == 3\n#include <shadow_sample_tent>\nfloat sampleShadowMapFiltered9(TEXTURE2D_SHADOW_PARAM(shadowMap),vec3 shadowCoord,vec4 shadowmapSize){float attenuation;float fetchesWeights[9];vec2 fetchesUV[9];sampleShadowComputeSamplesTent5x5(shadowmapSize,shadowCoord.xy,fetchesWeights,fetchesUV);attenuation=fetchesWeights[0]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[0].xy,shadowCoord.z));attenuation+=fetchesWeights[1]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[1].xy,shadowCoord.z));attenuation+=fetchesWeights[2]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[2].xy,shadowCoord.z));attenuation+=fetchesWeights[3]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[3].xy,shadowCoord.z));attenuation+=fetchesWeights[4]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[4].xy,shadowCoord.z));attenuation+=fetchesWeights[5]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[5].xy,shadowCoord.z));attenuation+=fetchesWeights[6]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[6].xy,shadowCoord.z));attenuation+=fetchesWeights[7]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[7].xy,shadowCoord.z));attenuation+=fetchesWeights[8]*SAMPLE_TEXTURE2D_SHADOW(shadowMap,vec3(fetchesUV[8].xy,shadowCoord.z));return attenuation;}\n#endif\nfloat getShadowFade(vec3 positionWS){vec3 camToPixel=positionWS-camera_Position;float distanceCamToPixel2=dot(camToPixel,camToPixel);return saturate(distanceCamToPixel2*scene_ShadowInfo.z+scene_ShadowInfo.w);}float sampleShadowMap(){\n#if SCENE_SHADOW_CASCADED_COUNT == 1\nvec3 shadowCoord=v_shadowCoord;\n#else\nvec3 shadowCoord=getShadowCoord();\n#endif\nfloat attenuation=1.0;if(shadowCoord.z>0.0&&shadowCoord.z<1.0){\n#if SCENE_SHADOW_TYPE == 1\nattenuation=SAMPLE_TEXTURE2D_SHADOW(scene_ShadowMap,shadowCoord);\n#endif\n#if SCENE_SHADOW_TYPE == 2\nattenuation=sampleShadowMapFiltered4(scene_ShadowMap,shadowCoord,scene_ShadowMapSize);\n#endif\n#if SCENE_SHADOW_TYPE == 3\nattenuation=sampleShadowMapFiltered9(scene_ShadowMap,shadowCoord,scene_ShadowMapSize);\n#endif\nfloat shadowFade=getShadowFade(v_pos);attenuation=mix(1.0,mix(attenuation,1.0,shadowFade),scene_ShadowInfo.x);}return attenuation;}\n#endif\n"; // eslint-disable-line
3620
3297
 
3621
3298
  var shadow_sample_tent = "#define GLSLIFY 1\nfloat sampleShadowGetIRTriangleTexelArea(float triangleHeight){return triangleHeight-0.5;}void sampleShadowGetTexelAreasTent3x3(float offset,out vec4 computedArea,out vec4 computedAreaUncut){float a=offset+0.5;float offsetSquaredHalved=a*a*0.5;computedAreaUncut.x=computedArea.x=offsetSquaredHalved-offset;computedAreaUncut.w=computedArea.w=offsetSquaredHalved;computedAreaUncut.y=sampleShadowGetIRTriangleTexelArea(1.5-offset);float clampedOffsetLeft=min(offset,0.0);float areaOfSmallLeftTriangle=clampedOffsetLeft*clampedOffsetLeft;computedArea.y=computedAreaUncut.y-areaOfSmallLeftTriangle;computedAreaUncut.z=sampleShadowGetIRTriangleTexelArea(1.5+offset);float clampedOffsetRight=max(offset,0.0);float areaOfSmallRightTriangle=clampedOffsetRight*clampedOffsetRight;computedArea.z=computedAreaUncut.z-areaOfSmallRightTriangle;}void sampleShadowGetTexelWeightsTent5x5(float offset,out vec3 texelsWeightsA,out vec3 texelsWeightsB){vec4 areaFrom3texelTriangle;vec4 areaUncutFrom3texelTriangle;sampleShadowGetTexelAreasTent3x3(offset,areaFrom3texelTriangle,areaUncutFrom3texelTriangle);texelsWeightsA.x=0.16*(areaFrom3texelTriangle.x);texelsWeightsA.y=0.16*(areaUncutFrom3texelTriangle.y);texelsWeightsA.z=0.16*(areaFrom3texelTriangle.y+1.0);texelsWeightsB.x=0.16*(areaFrom3texelTriangle.z+1.0);texelsWeightsB.y=0.16*(areaUncutFrom3texelTriangle.z);texelsWeightsB.z=0.16*(areaFrom3texelTriangle.w);}void sampleShadowComputeSamplesTent5x5(vec4 shadowMapTextureTexelSize,vec2 coord,out float fetchesWeights[9],out vec2 fetchesUV[9]){vec2 tentCenterInTexelSpace=coord.xy*shadowMapTextureTexelSize.zw;vec2 centerOfFetchesInTexelSpace=floor(tentCenterInTexelSpace+0.5);vec2 offsetFromTentCenterToCenterOfFetches=tentCenterInTexelSpace-centerOfFetchesInTexelSpace;vec3 texelsWeightsUA,texelsWeightsUB;vec3 texelsWeightsVA,texelsWeightsVB;sampleShadowGetTexelWeightsTent5x5(offsetFromTentCenterToCenterOfFetches.x,texelsWeightsUA,texelsWeightsUB);sampleShadowGetTexelWeightsTent5x5(offsetFromTentCenterToCenterOfFetches.y,texelsWeightsVA,texelsWeightsVB);vec3 fetchesWeightsU=vec3(texelsWeightsUA.xz,texelsWeightsUB.y)+vec3(texelsWeightsUA.y,texelsWeightsUB.xz);vec3 fetchesWeightsV=vec3(texelsWeightsVA.xz,texelsWeightsVB.y)+vec3(texelsWeightsVA.y,texelsWeightsVB.xz);vec3 fetchesOffsetsU=vec3(texelsWeightsUA.y,texelsWeightsUB.xz)/fetchesWeightsU.xyz+vec3(-2.5,-0.5,1.5);vec3 fetchesOffsetsV=vec3(texelsWeightsVA.y,texelsWeightsVB.xz)/fetchesWeightsV.xyz+vec3(-2.5,-0.5,1.5);fetchesOffsetsU*=shadowMapTextureTexelSize.xxx;fetchesOffsetsV*=shadowMapTextureTexelSize.yyy;vec2 bilinearFetchOrigin=centerOfFetchesInTexelSpace*shadowMapTextureTexelSize.xy;fetchesUV[0]=bilinearFetchOrigin+vec2(fetchesOffsetsU.x,fetchesOffsetsV.x);fetchesUV[1]=bilinearFetchOrigin+vec2(fetchesOffsetsU.y,fetchesOffsetsV.x);fetchesUV[2]=bilinearFetchOrigin+vec2(fetchesOffsetsU.z,fetchesOffsetsV.x);fetchesUV[3]=bilinearFetchOrigin+vec2(fetchesOffsetsU.x,fetchesOffsetsV.y);fetchesUV[4]=bilinearFetchOrigin+vec2(fetchesOffsetsU.y,fetchesOffsetsV.y);fetchesUV[5]=bilinearFetchOrigin+vec2(fetchesOffsetsU.z,fetchesOffsetsV.y);fetchesUV[6]=bilinearFetchOrigin+vec2(fetchesOffsetsU.x,fetchesOffsetsV.z);fetchesUV[7]=bilinearFetchOrigin+vec2(fetchesOffsetsU.y,fetchesOffsetsV.z);fetchesUV[8]=bilinearFetchOrigin+vec2(fetchesOffsetsU.z,fetchesOffsetsV.z);fetchesWeights[0]=fetchesWeightsU.x*fetchesWeightsV.x;fetchesWeights[1]=fetchesWeightsU.y*fetchesWeightsV.x;fetchesWeights[2]=fetchesWeightsU.z*fetchesWeightsV.x;fetchesWeights[3]=fetchesWeightsU.x*fetchesWeightsV.y;fetchesWeights[4]=fetchesWeightsU.y*fetchesWeightsV.y;fetchesWeights[5]=fetchesWeightsU.z*fetchesWeightsV.y;fetchesWeights[6]=fetchesWeightsU.x*fetchesWeightsV.z;fetchesWeights[7]=fetchesWeightsU.y*fetchesWeightsV.z;fetchesWeights[8]=fetchesWeightsU.z*fetchesWeightsV.z;}"; // eslint-disable-line
3622
3299
 
@@ -3731,16 +3408,22 @@ var ShaderFactory = /*#__PURE__*/ function() {
3731
3408
  }
3732
3409
  ShaderLib[includeName] = includeSource;
3733
3410
  };
3734
- ShaderFactory.parseIncludes = function parseIncludes(src) {
3411
+ ShaderFactory.unRegisterInclude = function unRegisterInclude(includeName) {
3412
+ delete ShaderLib[includeName];
3413
+ };
3414
+ /**
3415
+ * @param regex The default regex is for engine's builtin glsl `#include` syntax,
3416
+ * since `ShaderLab` use the same parsing function but different syntax for `#include` --- `/^[ \t]*#include +"([\w\d.]+)"/gm`
3417
+ */ ShaderFactory.parseIncludes = function parseIncludes(src, regex) {
3418
+ if (regex === void 0) regex = /^[ \t]*#include +<([\w\d.]+)>/gm;
3735
3419
  var replace = function replace(match, slice) {
3736
3420
  var replace = ShaderLib[slice];
3737
3421
  if (replace === undefined) {
3738
3422
  Logger.error('Shader slice "' + match.trim() + '" not founded.');
3739
3423
  return "";
3740
3424
  }
3741
- return ShaderFactory.parseIncludes(replace);
3425
+ return ShaderFactory.parseIncludes(replace, regex);
3742
3426
  };
3743
- var regex = /^[ \t]*#include +<([\w\d.]+)>/gm;
3744
3427
  return src.replace(regex, replace);
3745
3428
  };
3746
3429
  /**
@@ -3851,16 +3534,6 @@ var ShaderFactory = /*#__PURE__*/ function() {
3851
3534
  return ShaderPart;
3852
3535
  }();
3853
3536
 
3854
- /**
3855
- * Shader data grouping.
3856
- */ var ShaderDataGroup;
3857
- (function(ShaderDataGroup) {
3858
- ShaderDataGroup[ShaderDataGroup[/** Scene group. */ "Scene"] = 0] = "Scene";
3859
- ShaderDataGroup[ShaderDataGroup[/** Camera group. */ "Camera"] = 1] = "Camera";
3860
- ShaderDataGroup[ShaderDataGroup[/** Renderer group. */ "Renderer"] = 2] = "Renderer";
3861
- ShaderDataGroup[ShaderDataGroup[/** material group. */ "Material"] = 3] = "Material";
3862
- })(ShaderDataGroup || (ShaderDataGroup = {}));
3863
-
3864
3537
  /**
3865
3538
  * Color Space.
3866
3539
  */ exports.ColorSpace = void 0;
@@ -4070,6 +3743,16 @@ var ShaderFactory = /*#__PURE__*/ function() {
4070
3743
  this.textureUniforms = [];
4071
3744
  };
4072
3745
 
3746
+ /**
3747
+ * Shader data grouping.
3748
+ */ var ShaderDataGroup;
3749
+ (function(ShaderDataGroup) {
3750
+ ShaderDataGroup[ShaderDataGroup[/** Scene group. */ "Scene"] = 0] = "Scene";
3751
+ ShaderDataGroup[ShaderDataGroup[/** Camera group. */ "Camera"] = 1] = "Camera";
3752
+ ShaderDataGroup[ShaderDataGroup[/** Renderer group. */ "Renderer"] = 2] = "Renderer";
3753
+ ShaderDataGroup[ShaderDataGroup[/** material group. */ "Material"] = 3] = "Material";
3754
+ })(ShaderDataGroup || (ShaderDataGroup = {}));
3755
+
4073
3756
  /**
4074
3757
  * Shader program, corresponding to the GPU shader program.
4075
3758
  * @internal
@@ -4365,6 +4048,7 @@ var ShaderFactory = /*#__PURE__*/ function() {
4365
4048
  break;
4366
4049
  case gl.SAMPLER_2D:
4367
4050
  case gl.SAMPLER_CUBE:
4051
+ case gl.UNSIGNED_INT_SAMPLER_2D:
4368
4052
  case gl.SAMPLER_2D_ARRAY:
4369
4053
  case gl.SAMPLER_2D_SHADOW:
4370
4054
  var defaultTexture;
@@ -4375,6 +4059,9 @@ var ShaderFactory = /*#__PURE__*/ function() {
4375
4059
  case gl.SAMPLER_CUBE:
4376
4060
  defaultTexture = _this._engine._magentaTextureCube;
4377
4061
  break;
4062
+ case gl.UNSIGNED_INT_SAMPLER_2D:
4063
+ defaultTexture = _this._engine._uintMagentaTexture2D;
4064
+ break;
4378
4065
  case gl.SAMPLER_2D_ARRAY:
4379
4066
  defaultTexture = _this._engine._magentaTexture2DArray;
4380
4067
  break;
@@ -5464,6 +5151,57 @@ var GraphicsResource = /*#__PURE__*/ function(ReferResource1) {
5464
5151
  return GraphicsResource;
5465
5152
  }(ReferResource);
5466
5153
 
5154
+ /**
5155
+ * The filter mode of the texture.
5156
+ */ exports.TextureFilterMode = void 0;
5157
+ (function(TextureFilterMode) {
5158
+ TextureFilterMode[TextureFilterMode[/** Point filtering. */ "Point"] = 0] = "Point";
5159
+ TextureFilterMode[TextureFilterMode[/** Bilinear filtering. */ "Bilinear"] = 1] = "Bilinear";
5160
+ TextureFilterMode[TextureFilterMode[/** Trilinear filtering. */ "Trilinear"] = 2] = "Trilinear";
5161
+ })(exports.TextureFilterMode || (exports.TextureFilterMode = {}));
5162
+
5163
+ /**
5164
+ * Texture format enumeration.
5165
+ */ exports.TextureFormat = void 0;
5166
+ (function(TextureFormat) {
5167
+ TextureFormat[TextureFormat[/** RGB format, 8 bits per channel. */ "R8G8B8"] = 0] = "R8G8B8";
5168
+ TextureFormat[TextureFormat[/** RGBA format, 8 bits per channel. */ "R8G8B8A8"] = 1] = "R8G8B8A8";
5169
+ TextureFormat[TextureFormat[/** RGBA format, 4 bits per channel. */ "R4G4B4A4"] = 2] = "R4G4B4A4";
5170
+ TextureFormat[TextureFormat[/** RGBA format, 5 bits in R channel, 5 bits in G channel, 5 bits in B channel, 1 bit in A channel. */ "R5G5B5A1"] = 3] = "R5G5B5A1";
5171
+ TextureFormat[TextureFormat[/** RGB format, 5 bits in R channel, 6 bits in G channel, 5 bits in B channel. */ "R5G6B5"] = 4] = "R5G6B5";
5172
+ TextureFormat[TextureFormat[/** Transparent format, 8 bits. */ "Alpha8"] = 5] = "Alpha8";
5173
+ TextureFormat[TextureFormat[/** Luminance/alpha in RGB channel, alpha in A channel. */ "LuminanceAlpha"] = 6] = "LuminanceAlpha";
5174
+ TextureFormat[TextureFormat[/** RGBA format, 16 bits per channel. */ "R16G16B16A16"] = 7] = "R16G16B16A16";
5175
+ TextureFormat[TextureFormat[/** RGBA format, 32 bits per channel. */ "R32G32B32A32"] = 8] = "R32G32B32A32";
5176
+ TextureFormat[TextureFormat[/** RGBA unsigned integer format, 32 bits per channel. */ "R32G32B32A32_UInt"] = 9] = "R32G32B32A32_UInt";
5177
+ TextureFormat[TextureFormat[/** RGB compressed format, 4 bits per pixel. */ "BC1"] = 10] = "BC1";
5178
+ TextureFormat[TextureFormat[/** RGBA compressed format, 8 bits per pixel. */ "BC3"] = 11] = "BC3";
5179
+ TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 4x4 pixel block. */ "BC7"] = 12] = "BC7";
5180
+ TextureFormat[TextureFormat[/** RGB compressed format, 4 bits per pixel. */ "ETC1_RGB"] = 13] = "ETC1_RGB";
5181
+ TextureFormat[TextureFormat[/** RGB compressed format, 4 bits per pixel. */ "ETC2_RGB"] = 14] = "ETC2_RGB";
5182
+ TextureFormat[TextureFormat[/** RGBA compressed format, 5 bits per pixel, 4 bit in RGB, 1 bit in A. */ "ETC2_RGBA5"] = 15] = "ETC2_RGBA5";
5183
+ TextureFormat[TextureFormat[/** RGB compressed format, 8 bits per pixel. */ "ETC2_RGBA8"] = 16] = "ETC2_RGBA8";
5184
+ TextureFormat[TextureFormat[/** RGB compressed format, 2 bits per pixel. */ "PVRTC_RGB2"] = 17] = "PVRTC_RGB2";
5185
+ TextureFormat[TextureFormat[/** RGBA compressed format, 2 bits per pixel. */ "PVRTC_RGBA2"] = 18] = "PVRTC_RGBA2";
5186
+ TextureFormat[TextureFormat[/** RGB compressed format, 4 bits per pixel. */ "PVRTC_RGB4"] = 19] = "PVRTC_RGB4";
5187
+ TextureFormat[TextureFormat[/** RGBA compressed format, 4 bits per pixel. */ "PVRTC_RGBA4"] = 20] = "PVRTC_RGBA4";
5188
+ TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 4x4 pixel block. */ "ASTC_4x4"] = 21] = "ASTC_4x4";
5189
+ TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 5x5 pixel block. */ "ASTC_5x5"] = 22] = "ASTC_5x5";
5190
+ TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 6x6 pixel block. */ "ASTC_6x6"] = 23] = "ASTC_6x6";
5191
+ TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 8x8 pixel block. */ "ASTC_8x8"] = 24] = "ASTC_8x8";
5192
+ TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 10x10 pixel block. */ "ASTC_10x10"] = 25] = "ASTC_10x10";
5193
+ TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 12x12 pixel block. */ "ASTC_12x12"] = 26] = "ASTC_12x12";
5194
+ TextureFormat[TextureFormat[/** Automatic depth format, engine will automatically select the supported precision. */ "Depth"] = 27] = "Depth";
5195
+ TextureFormat[TextureFormat[/** Automatic depth stencil format, engine will automatically select the supported precision. */ "DepthStencil"] = 28] = "DepthStencil";
5196
+ TextureFormat[TextureFormat[/** 16-bit depth format. */ "Depth16"] = 29] = "Depth16";
5197
+ TextureFormat[TextureFormat[/** 24-bit depth format. */ "Depth24"] = 30] = "Depth24";
5198
+ TextureFormat[TextureFormat[/** 32-bit depth format. */ "Depth32"] = 31] = "Depth32";
5199
+ TextureFormat[TextureFormat[/** 16-bit depth + 8-bit stencil format. */ "Depth24Stencil8"] = 32] = "Depth24Stencil8";
5200
+ TextureFormat[TextureFormat[/** 32-bit depth + 8-bit stencil format. */ "Depth32Stencil8"] = 33] = "Depth32Stencil8";
5201
+ TextureFormat[TextureFormat[/** @deprecated Use `TextureFormat.BC1` instead. */ "DXT1"] = 34] = "DXT1";
5202
+ TextureFormat[TextureFormat[/** @deprecated Use `TextureFormat.BC3` instead. */ "DXT5"] = 35] = "DXT5";
5203
+ })(exports.TextureFormat || (exports.TextureFormat = {}));
5204
+
5467
5205
  /**
5468
5206
  * The base class of texture, contains some common functions of texture-related classes.
5469
5207
  */ var Texture = /*#__PURE__*/ function(GraphicsResource1) {
@@ -5520,6 +5258,12 @@ var GraphicsResource = /*#__PURE__*/ function(ReferResource1) {
5520
5258
  _proto._getMipmapCount = function _getMipmapCount() {
5521
5259
  return this._mipmap ? Math.floor(Math.log2(Math.max(this._width, this._height))) + 1 : 1;
5522
5260
  };
5261
+ _proto._isIntFormat = function _isIntFormat() {
5262
+ if (exports.TextureFormat.R32G32B32A32_UInt === this._format) {
5263
+ return true;
5264
+ }
5265
+ return false;
5266
+ };
5523
5267
  _create_class(Texture, [
5524
5268
  {
5525
5269
  key: "format",
@@ -5596,6 +5340,11 @@ var GraphicsResource = /*#__PURE__*/ function(ReferResource1) {
5596
5340
  },
5597
5341
  set: function set(value) {
5598
5342
  if (value === this._filterMode) return;
5343
+ if (value !== exports.TextureFilterMode.Point && this._isIntFormat()) {
5344
+ value = exports.TextureFilterMode.Point;
5345
+ Logger.warn("Int or UInt format texture only support TextureFilterMode.Point");
5346
+ return;
5347
+ }
5599
5348
  this._filterMode = value;
5600
5349
  this._platformTexture.filterMode = value;
5601
5350
  }
@@ -6722,7 +6471,7 @@ SlicedSpriteAssembler = __decorate([
6722
6471
  _this._byteLength = byteLength;
6723
6472
  _this._platformBuffer = engine._hardwareRenderer.createPlatformBuffer(type, byteLength, bufferUsage, data);
6724
6473
  if (readable) {
6725
- var buffer = (data.constructor === ArrayBuffer ? data : data.buffer).slice(0, byteLength);
6474
+ var buffer = data.constructor === ArrayBuffer ? data.slice(0) : data.buffer.slice(data.byteOffset, data.byteOffset + byteLength);
6726
6475
  _this._data = new Uint8Array(buffer);
6727
6476
  }
6728
6477
  }
@@ -7899,56 +7648,6 @@ var /**
7899
7648
  TextureDepthCompareFunction[TextureDepthCompareFunction[/** always pass. */ "Always"] = 7] = "Always";
7900
7649
  })(exports.TextureDepthCompareFunction || (exports.TextureDepthCompareFunction = {}));
7901
7650
 
7902
- /**
7903
- * The filter mode of the texture.
7904
- */ exports.TextureFilterMode = void 0;
7905
- (function(TextureFilterMode) {
7906
- TextureFilterMode[TextureFilterMode[/** Point filtering. */ "Point"] = 0] = "Point";
7907
- TextureFilterMode[TextureFilterMode[/** Bilinear filtering. */ "Bilinear"] = 1] = "Bilinear";
7908
- TextureFilterMode[TextureFilterMode[/** Trilinear filtering. */ "Trilinear"] = 2] = "Trilinear";
7909
- })(exports.TextureFilterMode || (exports.TextureFilterMode = {}));
7910
-
7911
- /**
7912
- * Texture format enumeration.
7913
- */ exports.TextureFormat = void 0;
7914
- (function(TextureFormat) {
7915
- TextureFormat[TextureFormat[/** RGB format, 8 bits per channel. */ "R8G8B8"] = 0] = "R8G8B8";
7916
- TextureFormat[TextureFormat[/** RGBA format, 8 bits per channel. */ "R8G8B8A8"] = 1] = "R8G8B8A8";
7917
- TextureFormat[TextureFormat[/** RGBA format, 4 bits per channel. */ "R4G4B4A4"] = 2] = "R4G4B4A4";
7918
- TextureFormat[TextureFormat[/** RGBA format, 5 bits in R channel, 5 bits in G channel, 5 bits in B channel, 1 bit in A channel. */ "R5G5B5A1"] = 3] = "R5G5B5A1";
7919
- TextureFormat[TextureFormat[/** RGB format, 5 bits in R channel, 6 bits in G channel, 5 bits in B channel. */ "R5G6B5"] = 4] = "R5G6B5";
7920
- TextureFormat[TextureFormat[/** Transparent format, 8 bits. */ "Alpha8"] = 5] = "Alpha8";
7921
- TextureFormat[TextureFormat[/** Luminance/alpha in RGB channel, alpha in A channel. */ "LuminanceAlpha"] = 6] = "LuminanceAlpha";
7922
- TextureFormat[TextureFormat[/** RGBA format, 16 bits per channel. */ "R16G16B16A16"] = 7] = "R16G16B16A16";
7923
- TextureFormat[TextureFormat[/** RGBA format, 32 bits per channel. */ "R32G32B32A32"] = 8] = "R32G32B32A32";
7924
- TextureFormat[TextureFormat[/** RGB compressed format, 4 bits per pixel. */ "BC1"] = 9] = "BC1";
7925
- TextureFormat[TextureFormat[/** RGBA compressed format, 8 bits per pixel. */ "BC3"] = 10] = "BC3";
7926
- TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 4x4 pixel block. */ "BC7"] = 11] = "BC7";
7927
- TextureFormat[TextureFormat[/** RGB compressed format, 4 bits per pixel. */ "ETC1_RGB"] = 12] = "ETC1_RGB";
7928
- TextureFormat[TextureFormat[/** RGB compressed format, 4 bits per pixel. */ "ETC2_RGB"] = 13] = "ETC2_RGB";
7929
- TextureFormat[TextureFormat[/** RGBA compressed format, 5 bits per pixel, 4 bit in RGB, 1 bit in A. */ "ETC2_RGBA5"] = 14] = "ETC2_RGBA5";
7930
- TextureFormat[TextureFormat[/** RGB compressed format, 8 bits per pixel. */ "ETC2_RGBA8"] = 15] = "ETC2_RGBA8";
7931
- TextureFormat[TextureFormat[/** RGB compressed format, 2 bits per pixel. */ "PVRTC_RGB2"] = 16] = "PVRTC_RGB2";
7932
- TextureFormat[TextureFormat[/** RGBA compressed format, 2 bits per pixel. */ "PVRTC_RGBA2"] = 17] = "PVRTC_RGBA2";
7933
- TextureFormat[TextureFormat[/** RGB compressed format, 4 bits per pixel. */ "PVRTC_RGB4"] = 18] = "PVRTC_RGB4";
7934
- TextureFormat[TextureFormat[/** RGBA compressed format, 4 bits per pixel. */ "PVRTC_RGBA4"] = 19] = "PVRTC_RGBA4";
7935
- TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 4x4 pixel block. */ "ASTC_4x4"] = 20] = "ASTC_4x4";
7936
- TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 5x5 pixel block. */ "ASTC_5x5"] = 21] = "ASTC_5x5";
7937
- TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 6x6 pixel block. */ "ASTC_6x6"] = 22] = "ASTC_6x6";
7938
- TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 8x8 pixel block. */ "ASTC_8x8"] = 23] = "ASTC_8x8";
7939
- TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 10x10 pixel block. */ "ASTC_10x10"] = 24] = "ASTC_10x10";
7940
- TextureFormat[TextureFormat[/** RGB(A) compressed format, 128 bits per 12x12 pixel block. */ "ASTC_12x12"] = 25] = "ASTC_12x12";
7941
- TextureFormat[TextureFormat[/** Automatic depth format, engine will automatically select the supported precision. */ "Depth"] = 26] = "Depth";
7942
- TextureFormat[TextureFormat[/** Automatic depth stencil format, engine will automatically select the supported precision. */ "DepthStencil"] = 27] = "DepthStencil";
7943
- TextureFormat[TextureFormat[/** 16-bit depth format. */ "Depth16"] = 28] = "Depth16";
7944
- TextureFormat[TextureFormat[/** 24-bit depth format. */ "Depth24"] = 29] = "Depth24";
7945
- TextureFormat[TextureFormat[/** 32-bit depth format. */ "Depth32"] = 30] = "Depth32";
7946
- TextureFormat[TextureFormat[/** 16-bit depth + 8-bit stencil format. */ "Depth24Stencil8"] = 31] = "Depth24Stencil8";
7947
- TextureFormat[TextureFormat[/** 32-bit depth + 8-bit stencil format. */ "Depth32Stencil8"] = 32] = "Depth32Stencil8";
7948
- TextureFormat[TextureFormat[/** @deprecated Use `TextureFormat.BC1` instead. */ "DXT1"] = 33] = "DXT1";
7949
- TextureFormat[TextureFormat[/** @deprecated Use `TextureFormat.BC3` instead. */ "DXT5"] = 34] = "DXT5";
7950
- })(exports.TextureFormat || (exports.TextureFormat = {}));
7951
-
7952
7651
  /**
7953
7652
  * Texture usage.
7954
7653
  */ exports.TextureUsage = void 0;
@@ -8132,7 +7831,7 @@ var /**
8132
7831
  _this._mipmapCount = _this._getMipmapCount();
8133
7832
  _this._isDepthTexture = format == exports.TextureFormat.Depth || format == exports.TextureFormat.DepthStencil || format == exports.TextureFormat.Depth16 || format == exports.TextureFormat.Depth24 || format == exports.TextureFormat.Depth32 || format == exports.TextureFormat.Depth24Stencil8 || format == exports.TextureFormat.Depth32Stencil8;
8134
7833
  _this._platformTexture = engine._hardwareRenderer.createPlatformTexture2D(_assert_this_initialized(_this));
8135
- _this.filterMode = exports.TextureFilterMode.Bilinear;
7834
+ _this.filterMode = _this._isIntFormat() ? exports.TextureFilterMode.Point : exports.TextureFilterMode.Bilinear;
8136
7835
  _this.wrapModeU = _this.wrapModeV = exports.TextureWrapMode.Repeat;
8137
7836
  return _this;
8138
7837
  }
@@ -9931,6 +9630,10 @@ var VertexElementIndex;
9931
9630
  var sphereInfo = primitiveInfo;
9932
9631
  PrimitiveMesh._setSphereData(this.resource, sphereInfo.radius, sphereInfo.segments, sphereInfo.noLongerAccessible, true, sphereInfo.vertexBuffer);
9933
9632
  break;
9633
+ case 7:
9634
+ var CCSphereInfo = primitiveInfo;
9635
+ PrimitiveMesh._setSubdivisionSurfaceSphereData(this.resource, CCSphereInfo.radius, CCSphereInfo.step, CCSphereInfo.noLongerAccessible, true, CCSphereInfo.vertexBuffer);
9636
+ break;
9934
9637
  case 1:
9935
9638
  var cuboidInfo = primitiveInfo;
9936
9639
  PrimitiveMesh._setCuboidData(this.resource, cuboidInfo.width, cuboidInfo.height, cuboidInfo.depth, cuboidInfo.noLongerAccessible, true, cuboidInfo.vertexBuffer);
@@ -9968,6 +9671,7 @@ var PrimitiveType;
9968
9671
  PrimitiveType[PrimitiveType["Torus"] = 4] = "Torus";
9969
9672
  PrimitiveType[PrimitiveType["Cone"] = 5] = "Cone";
9970
9673
  PrimitiveType[PrimitiveType["Capsule"] = 6] = "Capsule";
9674
+ PrimitiveType[PrimitiveType["CCSphere"] = 7] = "CCSphere";
9971
9675
  })(PrimitiveType || (PrimitiveType = {}));
9972
9676
  /**
9973
9677
  * @internal
@@ -9989,6 +9693,19 @@ var PrimitiveType;
9989
9693
  }
9990
9694
  return SphereRestoreInfo;
9991
9695
  }(PrimitiveRestoreInfo);
9696
+ /**
9697
+ * @internal
9698
+ */ var SubdivisionSurfaceSphereRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
9699
+ _inherits(SubdivisionSurfaceSphereRestoreInfo, PrimitiveRestoreInfo);
9700
+ function SubdivisionSurfaceSphereRestoreInfo(radius, step, vertexBuffer, noLongerAccessible) {
9701
+ var _this;
9702
+ _this = PrimitiveRestoreInfo.call(this, 7, vertexBuffer, noLongerAccessible) || this;
9703
+ _this.radius = radius;
9704
+ _this.step = step;
9705
+ return _this;
9706
+ }
9707
+ return SubdivisionSurfaceSphereRestoreInfo;
9708
+ }(PrimitiveRestoreInfo);
9992
9709
  /**
9993
9710
  * @internal
9994
9711
  */ var CuboidRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
@@ -10103,6 +9820,24 @@ var PrimitiveType;
10103
9820
  return sphereMesh;
10104
9821
  };
10105
9822
  /**
9823
+ * Create a sphere mesh by implementing Catmull-Clark Surface Subdivision Algorithm.
9824
+ * Max step is limited to 6.
9825
+ * @param engine - Engine
9826
+ * @param radius - Sphere radius
9827
+ * @param step - Number of subdiv steps
9828
+ * @param noLongerAccessible - No longer access the vertices of the mesh after creation
9829
+ * @returns Sphere model mesh
9830
+ */ PrimitiveMesh.createSubdivisionSurfaceSphere = function createSubdivisionSurfaceSphere(engine, radius, step, noLongerAccessible) {
9831
+ if (radius === void 0) radius = 0.5;
9832
+ if (step === void 0) step = 3;
9833
+ if (noLongerAccessible === void 0) noLongerAccessible = true;
9834
+ var sphereMesh = new ModelMesh(engine);
9835
+ PrimitiveMesh._setSubdivisionSurfaceSphereData(sphereMesh, radius, step, noLongerAccessible, false);
9836
+ var vertexBuffer = sphereMesh.vertexBufferBindings[0].buffer;
9837
+ engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(sphereMesh, new SubdivisionSurfaceSphereRestoreInfo(radius, step, vertexBuffer, noLongerAccessible)));
9838
+ return sphereMesh;
9839
+ };
9840
+ /**
10106
9841
  * Create a cuboid mesh.
10107
9842
  * @param engine - Engine
10108
9843
  * @param width - Cuboid width
@@ -10232,6 +9967,90 @@ var PrimitiveType;
10232
9967
  };
10233
9968
  /**
10234
9969
  * @internal
9970
+ */ PrimitiveMesh._setSubdivisionSurfaceSphereData = function _setSubdivisionSurfaceSphereData(sphereMesh, radius, step, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
9971
+ // Max step is limited to 6. Because 7 step will generate a single mesh with over 98306 vertices
9972
+ step = miniprogram.MathUtil.clamp(Math.floor(step), 1, 6);
9973
+ var positions = new Float32Array(3 * (6 * Math.pow(4, step) + 2));
9974
+ var cells = new Float32Array(24 * Math.pow(4, step));
9975
+ PrimitiveMesh._subdiveCatmullClark(step, positions, cells);
9976
+ var positionCount = positions.length / 3;
9977
+ var cellsCount = cells.length / 4;
9978
+ var poleOffset = positionCount + Math.pow(2, step + 1) - 1;
9979
+ // 16 extra vertices for pole uv
9980
+ // 2 vertices at each pole are idle
9981
+ var vertexCount = poleOffset + 16;
9982
+ var vertices = new Float32Array(vertexCount * 8);
9983
+ var indices = PrimitiveMesh._generateIndices(sphereMesh.engine, positionCount, cellsCount * 6);
9984
+ var seamCount = 0;
9985
+ var seamVertices = {};
9986
+ // Get normals, uvs, and scale to radius
9987
+ for(var i = 0; i < positionCount; i++){
9988
+ var offset = 3 * i;
9989
+ var x = positions[offset];
9990
+ var y = positions[offset + 1];
9991
+ var z = positions[offset + 2];
9992
+ var reciprocalLength = 1 / Math.sqrt(x * x + y * y + z * z);
9993
+ x *= reciprocalLength;
9994
+ y *= reciprocalLength;
9995
+ z *= reciprocalLength;
9996
+ offset = 8 * i;
9997
+ vertices[offset] = x * radius;
9998
+ vertices[offset + 1] = y * radius;
9999
+ vertices[offset + 2] = z * radius;
10000
+ vertices[offset + 3] = x;
10001
+ vertices[offset + 4] = y;
10002
+ vertices[offset + 5] = z;
10003
+ vertices[offset + 6] = (Math.PI - Math.atan2(z, x)) / (2 * Math.PI);
10004
+ vertices[offset + 7] = Math.acos(y) / Math.PI;
10005
+ if (vertices[offset + 6] === 0) {
10006
+ // Generate seam vertex
10007
+ var seamOffset = 8 * (positionCount + seamCount++);
10008
+ vertices.set(vertices.subarray(offset, offset + 8), seamOffset);
10009
+ vertices[seamOffset + 6] = 1.0;
10010
+ // Cache seam vertex
10011
+ seamVertices[offset / 8] = seamOffset / 8;
10012
+ }
10013
+ }
10014
+ // Get indices
10015
+ var offset1 = 0;
10016
+ this._spherePoleIdx = 0;
10017
+ for(var i1 = 0; i1 < cellsCount; i1++){
10018
+ var idx = 4 * i1;
10019
+ var indexA = cells[idx];
10020
+ var indexB = cells[idx + 1];
10021
+ var indexC = cells[idx + 2];
10022
+ var indexD = cells[idx + 3];
10023
+ // Handle seam by replacing vertex index to seam vertex index if necessary
10024
+ var floatIndexA = 8 * indexA;
10025
+ var floatIndexB = 8 * indexB;
10026
+ var floatIndexC = 8 * indexC;
10027
+ var floatIndexD = 8 * indexD;
10028
+ // If center Z is negative
10029
+ if (vertices[floatIndexA + 2] + vertices[floatIndexB + 2] + vertices[floatIndexC + 2] < 0) {
10030
+ vertices[floatIndexA + 6] === 0 && (indexA = seamVertices[indexA]);
10031
+ vertices[floatIndexB + 6] === 0 && (indexB = seamVertices[indexB]);
10032
+ vertices[floatIndexC + 6] === 0 && (indexC = seamVertices[indexC]);
10033
+ vertices[floatIndexD + 6] === 0 && (indexD = seamVertices[indexD]);
10034
+ }
10035
+ indices[offset1] = indexA;
10036
+ indices[offset1 + 1] = indexB;
10037
+ indices[offset1 + 2] = indexC;
10038
+ this._generateAndReplacePoleUV(indices, vertices, offset1, poleOffset);
10039
+ indices[offset1 + 3] = indexA;
10040
+ indices[offset1 + 4] = indexC;
10041
+ indices[offset1 + 5] = indexD;
10042
+ this._generateAndReplacePoleUV(indices, vertices, offset1 + 3, poleOffset);
10043
+ offset1 += 6;
10044
+ }
10045
+ if (!isRestoreMode) {
10046
+ var bounds = sphereMesh.bounds;
10047
+ bounds.min.set(-radius, -radius, -radius);
10048
+ bounds.max.set(radius, radius, radius);
10049
+ }
10050
+ PrimitiveMesh._initialize(sphereMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
10051
+ };
10052
+ /**
10053
+ * @internal
10235
10054
  */ PrimitiveMesh._setSphereData = function _setSphereData(sphereMesh, radius, segments, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
10236
10055
  segments = Math.max(2, Math.floor(segments));
10237
10056
  var count = segments + 1;
@@ -10292,6 +10111,135 @@ var PrimitiveType;
10292
10111
  };
10293
10112
  /**
10294
10113
  * @internal
10114
+ */ PrimitiveMesh._subdiveCatmullClark = function _subdiveCatmullClark(step, positions, cells) {
10115
+ var edges = new Map();
10116
+ var faces = new Array();
10117
+ positions.set(PrimitiveMesh._sphereSeedPositions);
10118
+ cells.set(PrimitiveMesh._sphereSeedCells);
10119
+ for(var i = 0; i < step; i++){
10120
+ var cellCount = 6 * Math.pow(4, i);
10121
+ var positionCount = 4 * cellCount + 2;
10122
+ edges.clear();
10123
+ faces.length = 0;
10124
+ // Get cell face's facePoint
10125
+ for(var j = 0; j < cellCount; j++){
10126
+ var face = faces[j] = {
10127
+ facePoint: new miniprogram.Vector3(),
10128
+ adjacentEdges: new Array(4)
10129
+ };
10130
+ // Get cell's edgePoint
10131
+ for(var k = 0; k < 4; k++){
10132
+ var offset = 3 * cells[4 * j + k];
10133
+ face.facePoint.x += 0.25 * positions[offset];
10134
+ face.facePoint.y += 0.25 * positions[offset + 1];
10135
+ face.facePoint.z += 0.25 * positions[offset + 2];
10136
+ }
10137
+ // Get cell edges
10138
+ for(var k1 = 0; k1 < 4; k1++){
10139
+ var vertexIdxA = cells[4 * j + k1];
10140
+ var vertexIdxB = cells[4 * j + (k1 + 1) % 4];
10141
+ var edgeIdxKey = Math.min(vertexIdxA, vertexIdxB) * positionCount + Math.max(vertexIdxA, vertexIdxB);
10142
+ if (!edges.has(edgeIdxKey)) {
10143
+ var edge = {
10144
+ edgePoint: new miniprogram.Vector3(),
10145
+ edgePointIndex: undefined
10146
+ };
10147
+ var offsetA = 3 * vertexIdxA;
10148
+ var offsetB = 3 * vertexIdxB;
10149
+ edge.edgePoint.set(0.25 * (positions[offsetA] + positions[offsetB]), 0.25 * (positions[offsetA + 1] + positions[offsetB + 1]), 0.25 * (positions[offsetA + 2] + positions[offsetB + 2]));
10150
+ edges.set(edgeIdxKey, edge);
10151
+ }
10152
+ var edge1 = edges.get(edgeIdxKey);
10153
+ face.adjacentEdges[k1] = edge1;
10154
+ var edgePoint = edge1.edgePoint;
10155
+ var facePoint = face.facePoint;
10156
+ edgePoint.x += 0.25 * facePoint.x;
10157
+ edgePoint.y += 0.25 * facePoint.y;
10158
+ edgePoint.z += 0.25 * facePoint.z;
10159
+ }
10160
+ }
10161
+ var prePointCount = cellCount + 2;
10162
+ var edgePointOffset = prePointCount + cellCount;
10163
+ var pointIdx = 0;
10164
+ this._sphereEdgeIdx = 0;
10165
+ var preCells = cells.slice(0, 4 * cellCount);
10166
+ // Get New positions, which consists of updated positions of existing points, face points and edge points
10167
+ for(var j1 = 0; j1 < cellCount; j1++){
10168
+ // Add face point to new positions
10169
+ var face1 = faces[j1];
10170
+ face1.facePoint.copyToArray(positions, 3 * (prePointCount + j1));
10171
+ // Get the face point index
10172
+ var ic = prePointCount + j1;
10173
+ var id = void 0, ib = void 0, temp = void 0;
10174
+ // ia -- id -- ia
10175
+ // | | |
10176
+ // ib -- ic -- ib
10177
+ // | | |
10178
+ // ia -- id -- ia
10179
+ for(var k2 = 0; k2 < 4; k2++){
10180
+ // Get the updated existing point index
10181
+ var ia = preCells[pointIdx++];
10182
+ // ib and id share four edge points in one cell
10183
+ switch(k2){
10184
+ case 0:
10185
+ {
10186
+ var edgeB = face1.adjacentEdges[k2 % 4];
10187
+ var edgeD = face1.adjacentEdges[(k2 + 3) % 4];
10188
+ ib = this._calculateEdgeIndex(positions, edgeB, edgePointOffset);
10189
+ id = this._calculateEdgeIndex(positions, edgeD, edgePointOffset);
10190
+ temp = id;
10191
+ break;
10192
+ }
10193
+ case 1:
10194
+ case 2:
10195
+ {
10196
+ var edgeB1 = face1.adjacentEdges[k2 % 4];
10197
+ id = ib;
10198
+ ib = this._calculateEdgeIndex(positions, edgeB1, edgePointOffset);
10199
+ break;
10200
+ }
10201
+ case 3:
10202
+ {
10203
+ id = ib;
10204
+ ib = temp;
10205
+ break;
10206
+ }
10207
+ }
10208
+ var idx = 4 * (4 * j1 + k2);
10209
+ cells[idx] = ia;
10210
+ cells[idx + 1] = ib;
10211
+ cells[idx + 2] = ic;
10212
+ cells[idx + 3] = id;
10213
+ }
10214
+ }
10215
+ }
10216
+ };
10217
+ /**
10218
+ * Duplicate vertices at the poles and adjust their UV coordinates.
10219
+ */ PrimitiveMesh._generateAndReplacePoleUV = function _generateAndReplacePoleUV(indices, vertices, idx, poleOffset) {
10220
+ var v = vertices[8 * indices[idx] + 7];
10221
+ if (v === 0 || v === 1) {
10222
+ var offset = 8 * indices[idx];
10223
+ var addedOffset = 8 * (poleOffset + this._spherePoleIdx);
10224
+ vertices.set(vertices.subarray(offset, offset + 8), addedOffset);
10225
+ vertices[addedOffset + 6] = 0.5 * (vertices[offset + 6] + vertices[8 * indices[idx + 1] + 6] + vertices[8 * indices[idx + 2] + 6] - 0.5);
10226
+ indices[idx] = poleOffset + this._spherePoleIdx++;
10227
+ }
10228
+ };
10229
+ /**
10230
+ * Get edge point index for subdivision surface sphere.
10231
+ */ PrimitiveMesh._calculateEdgeIndex = function _calculateEdgeIndex(positions, edge, offset) {
10232
+ if (edge.edgePointIndex !== undefined) {
10233
+ return edge.edgePointIndex;
10234
+ } else {
10235
+ edge.edgePoint.copyToArray(positions, 3 * (offset + PrimitiveMesh._sphereEdgeIdx));
10236
+ var index = offset + PrimitiveMesh._sphereEdgeIdx++;
10237
+ edge.edgePointIndex = index;
10238
+ return index;
10239
+ }
10240
+ };
10241
+ /**
10242
+ * @internal
10295
10243
  */ PrimitiveMesh._setCuboidData = function _setCuboidData(cuboidMesh, width, height, depth, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
10296
10244
  var halfWidth = width / 2;
10297
10245
  var halfHeight = height / 2;
@@ -10693,7 +10641,7 @@ var PrimitiveType;
10693
10641
  var theta = thetaStart + u * thetaRange;
10694
10642
  var sinTheta = Math.sin(theta);
10695
10643
  var cosTheta = Math.cos(theta);
10696
- var curRadius = radius - y * radius;
10644
+ var curRadius = radius - v * radius;
10697
10645
  var posX = curRadius * sinTheta;
10698
10646
  var posY = y * unitHeight - halfHeight;
10699
10647
  var posZ = curRadius * cosTheta;
@@ -10827,8 +10775,8 @@ var PrimitiveType;
10827
10775
  indices[indicesOffset++] = d;
10828
10776
  indices[indicesOffset++] = c;
10829
10777
  }
10830
- PrimitiveMesh._createCapsuleCap(radius, height, radialSegments, thetaRange, torsoVertexCount, 1, vertices, indices, indicesOffset);
10831
- PrimitiveMesh._createCapsuleCap(radius, height, radialSegments, -thetaRange, torsoVertexCount + capVertexCount, -1, vertices, indices, indicesOffset + 6 * capRectangleCount);
10778
+ PrimitiveMesh._createCapsuleCap(radius, height, radialSegments, thetaStart, thetaRange, torsoVertexCount, 1, vertices, indices, indicesOffset);
10779
+ PrimitiveMesh._createCapsuleCap(radius, height, radialSegments, thetaStart, -thetaRange, torsoVertexCount + capVertexCount, -1, vertices, indices, indicesOffset + 6 * capRectangleCount);
10832
10780
  if (!isRestoreMode) {
10833
10781
  var bounds = capsuleMesh.bounds;
10834
10782
  bounds.min.set(-radius, -radius - halfHeight, -radius);
@@ -10869,7 +10817,7 @@ var PrimitiveType;
10869
10817
  }
10870
10818
  return indices;
10871
10819
  };
10872
- PrimitiveMesh._createCapsuleCap = function _createCapsuleCap(radius, height, radialSegments, capAlphaRange, offset, posIndex, vertices, indices, indicesOffset) {
10820
+ PrimitiveMesh._createCapsuleCap = function _createCapsuleCap(radius, height, radialSegments, thetaStart, thetaRange, offset, posIndex, vertices, indices, indicesOffset) {
10873
10821
  var radialCount = radialSegments + 1;
10874
10822
  var halfHeight = height * 0.5 * posIndex;
10875
10823
  var capVertexCount = radialCount * radialCount;
@@ -10882,12 +10830,12 @@ var PrimitiveType;
10882
10830
  var y = i * radialCountReciprocal | 0;
10883
10831
  var u = x * radialSegmentsReciprocal;
10884
10832
  var v = y * radialSegmentsReciprocal;
10885
- var alphaDelta = u * capAlphaRange;
10886
- var thetaDelta = v * Math.PI / 2;
10887
- var sinTheta = Math.sin(thetaDelta);
10888
- var posX = -radius * Math.cos(alphaDelta) * sinTheta;
10889
- var posY = radius * Math.cos(thetaDelta) * posIndex + halfHeight;
10890
- var posZ = radius * Math.sin(alphaDelta) * sinTheta;
10833
+ var theta = thetaStart + u * thetaRange;
10834
+ var alpha = v * Math.PI * 0.5;
10835
+ var sinAlpha = Math.sin(alpha);
10836
+ var posX = radius * Math.sin(theta) * sinAlpha;
10837
+ var posY = radius * Math.cos(alpha) * posIndex + halfHeight;
10838
+ var posZ = radius * Math.cos(theta) * sinAlpha;
10891
10839
  var index = (i + offset) * vertexFloatCount;
10892
10840
  // Position
10893
10841
  vertices[index++] = posX;
@@ -10921,29 +10869,91 @@ var PrimitiveType;
10921
10869
  (function() {
10922
10870
  PrimitiveMesh._tempVec30 = new miniprogram.Vector3();
10923
10871
  })();
10924
-
10925
- /**
10926
- * Mesh skin data, equal glTF skins define
10927
- */ var Skin = /*#__PURE__*/ function(EngineObject1) {
10928
- _inherits(Skin, EngineObject1);
10929
- function Skin(name) {
10930
- var _this;
10931
- _this = EngineObject1.call(this, null) || this;
10932
- _this.name = name;
10933
- _this._bones = [];
10934
- _this.inverseBindMatrices = []; // inverse bind matrix array
10935
- _this.joints = []; // joints name array, element type: string
10936
- _this.skeleton = "none"; // root bone name
10937
- return _this;
10938
- }
10939
- return Skin;
10940
- }(EngineObject);
10941
-
10942
- /**
10943
- * SkinnedMeshRenderer.
10944
- */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer1) {
10945
- _inherits(SkinnedMeshRenderer, MeshRenderer1);
10946
- function SkinnedMeshRenderer(entity) {
10872
+ (function() {
10873
+ PrimitiveMesh._sphereSeedPositions = new Float32Array([
10874
+ -1,
10875
+ 1,
10876
+ 1,
10877
+ -1,
10878
+ -1,
10879
+ 1,
10880
+ 1,
10881
+ -1,
10882
+ 1,
10883
+ 1,
10884
+ 1,
10885
+ 1,
10886
+ 1,
10887
+ -1,
10888
+ -1,
10889
+ 1,
10890
+ 1,
10891
+ -1,
10892
+ -1,
10893
+ -1,
10894
+ -1,
10895
+ -1,
10896
+ 1,
10897
+ -1
10898
+ ]);
10899
+ })();
10900
+ (function() {
10901
+ PrimitiveMesh._sphereSeedCells = new Float32Array([
10902
+ 0,
10903
+ 1,
10904
+ 2,
10905
+ 3,
10906
+ 3,
10907
+ 2,
10908
+ 4,
10909
+ 5,
10910
+ 5,
10911
+ 4,
10912
+ 6,
10913
+ 7,
10914
+ 7,
10915
+ 0,
10916
+ 3,
10917
+ 5,
10918
+ 7,
10919
+ 6,
10920
+ 1,
10921
+ 0,
10922
+ 6,
10923
+ 4,
10924
+ 2,
10925
+ 1
10926
+ ]);
10927
+ })();
10928
+ (function() {
10929
+ PrimitiveMesh._sphereEdgeIdx = 0;
10930
+ })();
10931
+ (function() {
10932
+ PrimitiveMesh._spherePoleIdx = 0;
10933
+ })();
10934
+
10935
+ /**
10936
+ * Mesh skin data, equal glTF skins define
10937
+ */ var Skin = /*#__PURE__*/ function(EngineObject1) {
10938
+ _inherits(Skin, EngineObject1);
10939
+ function Skin(name) {
10940
+ var _this;
10941
+ _this = EngineObject1.call(this, null) || this;
10942
+ _this.name = name;
10943
+ _this._bones = [];
10944
+ _this.inverseBindMatrices = []; // inverse bind matrix array
10945
+ _this.joints = []; // joints name array, element type: string
10946
+ _this.skeleton = "none"; // root bone name
10947
+ return _this;
10948
+ }
10949
+ return Skin;
10950
+ }(EngineObject);
10951
+
10952
+ /**
10953
+ * SkinnedMeshRenderer.
10954
+ */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer1) {
10955
+ _inherits(SkinnedMeshRenderer, MeshRenderer1);
10956
+ function SkinnedMeshRenderer(entity) {
10947
10957
  var _this;
10948
10958
  _this = MeshRenderer1.call(this, entity) || this;
10949
10959
  _this._localBounds = new miniprogram.BoundingBox();
@@ -11384,7 +11394,9 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
11384
11394
  this._batchedQueue = null;
11385
11395
  var _this = this, meshes = _this._meshes, vertexBuffers = _this._vertexBuffers, indiceBuffers = _this._indiceBuffers;
11386
11396
  for(var i = 0, n = meshes.length; i < n; ++i){
11387
- meshes[i].destroy();
11397
+ var mesh = meshes[i];
11398
+ mesh._addReferCount(-1);
11399
+ mesh.destroy();
11388
11400
  }
11389
11401
  this._meshes = null;
11390
11402
  for(var i1 = 0, n1 = vertexBuffers.length; i1 < n1; ++i1){
@@ -11407,7 +11419,7 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
11407
11419
  _proto._createMesh = function _createMesh(engine, index) {
11408
11420
  var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
11409
11421
  var mesh = new BufferMesh(engine, "BufferMesh" + index);
11410
- mesh.isGCIgnored = true;
11422
+ mesh._addReferCount(1);
11411
11423
  var vertexElements = [];
11412
11424
  var vertexStride = this.createVertexElements(vertexElements);
11413
11425
  // vertices
@@ -11465,8 +11477,10 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
11465
11477
  }
11466
11478
  mesh.addSubMesh(this._getSubMeshFromPool(vertexStartIndex, vertexCount));
11467
11479
  batchedQueue[curMeshIndex] = preElement;
11468
- this._vertexBuffers[_flushId].setData(vertices, 0, 0, vertexIndex);
11469
- this._indiceBuffers[_flushId].setData(indices, 0, 0, indiceIndex);
11480
+ // Set data option use Discard, or will resulted in performance slowdown when open antialias and cross-rendering of 3D and 2D elements.
11481
+ // Device: iphone X(16.7.2)、iphone 15 pro max(17.1.1)、iphone XR(17.1.2) etc.
11482
+ this._vertexBuffers[_flushId].setData(vertices, 0, 0, vertexIndex, exports.SetDataOptions.Discard);
11483
+ this._indiceBuffers[_flushId].setData(indices, 0, 0, indiceIndex, exports.SetDataOptions.Discard);
11470
11484
  };
11471
11485
  _proto._getSubMeshFromPool = function _getSubMeshFromPool(start, count) {
11472
11486
  var subMesh = this._subMeshPool.getFromPool();
@@ -12496,6 +12510,9 @@ var /**
12496
12510
  __decorate([
12497
12511
  assignmentClone
12498
12512
  ], SpriteMask.prototype, "influenceLayers", void 0);
12513
+ __decorate([
12514
+ ignoreClone
12515
+ ], SpriteMask.prototype, "_verticesData", void 0);
12499
12516
  __decorate([
12500
12517
  ignoreClone
12501
12518
  ], SpriteMask.prototype, "_sprite", void 0);
@@ -12779,8 +12796,8 @@ var /**
12779
12796
  } else {
12780
12797
  word += char;
12781
12798
  wordWidth += charInfo.xAdvance;
12782
- wordMaxAscent = lineMaxAscent = Math.max(wordMaxAscent, ascent);
12783
- wordMaxDescent = lineMaxDescent = Math.max(wordMaxDescent, descent);
12799
+ wordMaxAscent = Math.max(wordMaxAscent, ascent);
12800
+ wordMaxDescent = Math.max(wordMaxDescent, descent);
12784
12801
  }
12785
12802
  }
12786
12803
  }
@@ -12901,6 +12918,9 @@ var /**
12901
12918
  var baseline = Math.ceil(context.measureText(TextUtils._measureBaseline).width);
12902
12919
  var height = baseline * TextUtils._heightMultiplier;
12903
12920
  baseline = TextUtils._baselineMultiplier * baseline | 0;
12921
+ var _extendHeight = TextUtils._extendHeight;
12922
+ height += _extendHeight;
12923
+ baseline += _extendHeight * 0.5;
12904
12924
  canvas.width = width;
12905
12925
  canvas.height = height;
12906
12926
  context.font = fontString;
@@ -12935,6 +12955,7 @@ var /**
12935
12955
  }
12936
12956
  if (top !== -1 && bottom !== -1) {
12937
12957
  ascent = baseline - top;
12958
+ // Baseline belong to descent
12938
12959
  descent = bottom - baseline + 1;
12939
12960
  size = ascent + descent;
12940
12961
  }
@@ -13010,6 +13031,10 @@ var /**
13010
13031
  "fangsong"
13011
13032
  ];
13012
13033
  })();
13034
+ (function() {
13035
+ // _extendHeight used to extend the height of canvas, because in miniprogram performance is different from h5.
13036
+ /** @internal */ TextUtils._extendHeight = 0;
13037
+ })();
13013
13038
  (function() {
13014
13039
  /** These characters are all tall to help calculate the height required for text. */ TextUtils._measureString = "|\xc9q\xc5";
13015
13040
  })();
@@ -13100,7 +13125,8 @@ var /**
13100
13125
  _proto._createFontAtlas = function _createFontAtlas() {
13101
13126
  var _this = this, engine = _this._engine;
13102
13127
  var fontAtlas = new FontAtlas(engine);
13103
- var texture = new Texture2D(engine, 256, 256);
13128
+ var texture = new Texture2D(engine, 256, 256, exports.TextureFormat.R8G8B8A8, false);
13129
+ texture.filterMode = exports.TextureFilterMode.Bilinear;
13104
13130
  fontAtlas.texture = texture;
13105
13131
  fontAtlas.isGCIgnored = texture.isGCIgnored = true;
13106
13132
  this._fontAtlases.push(fontAtlas);
@@ -13338,7 +13364,7 @@ var /**
13338
13364
  /**
13339
13365
  * @internal
13340
13366
  */ _proto._render = function _render(context) {
13341
- if (this._text === "" || this.enableWrapping && this.width <= 0 || this.overflowMode === exports.OverflowMode.Truncate && this.height <= 0) {
13367
+ if (this._isTextNoVisible()) {
13342
13368
  return;
13343
13369
  }
13344
13370
  if (this._isContainDirtyFlag(0x10)) {
@@ -13430,8 +13456,8 @@ var /**
13430
13456
  }
13431
13457
  };
13432
13458
  _proto._updateLocalData = function _updateLocalData() {
13433
- var _this = this, color = _this.color, charRenderDatas = _this._charRenderDatas, charFont = _this._subFont;
13434
13459
  var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
13460
+ var _this = this, color = _this.color, charRenderDatas = _this._charRenderDatas, charFont = _this._subFont;
13435
13461
  var textMetrics = this.enableWrapping ? TextUtils.measureTextWithWrap(this) : TextUtils.measureTextWithoutWrap(this);
13436
13462
  var height = textMetrics.height, lines = textMetrics.lines, lineWidths = textMetrics.lineWidths, lineHeight = textMetrics.lineHeight, lineMaxSizes = textMetrics.lineMaxSizes;
13437
13463
  var charRenderDataPool = TextRenderer._charRenderDataPool;
@@ -13499,7 +13525,7 @@ var /**
13499
13525
  var left = startX * pixelsPerUnitReciprocal;
13500
13526
  var right = (startX + w) * pixelsPerUnitReciprocal;
13501
13527
  var top = (startY + ascent) * pixelsPerUnitReciprocal;
13502
- var bottom = (startY - descent + 1) * pixelsPerUnitReciprocal;
13528
+ var bottom = (startY - descent) * pixelsPerUnitReciprocal;
13503
13529
  localPositions.set(left, top, right, bottom);
13504
13530
  i === firstLine && (maxY = Math.max(maxY, top));
13505
13531
  minY = Math.min(minY, bottom);
@@ -13540,6 +13566,9 @@ var /**
13540
13566
  Renderer1.prototype._onTransformChanged.call(this, bit);
13541
13567
  this._setDirtyFlagTrue(0x4 | 0x8);
13542
13568
  };
13569
+ _proto._isTextNoVisible = function _isTextNoVisible() {
13570
+ return this._text === "" || this._fontSize === 0 || this.enableWrapping && this.width <= 0 || this.overflowMode === exports.OverflowMode.Truncate && this.height <= 0;
13571
+ };
13543
13572
  _create_class(TextRenderer, [
13544
13573
  {
13545
13574
  key: "color",
@@ -13742,6 +13771,16 @@ var /**
13742
13771
  get: /**
13743
13772
  * The bounding volume of the TextRenderer.
13744
13773
  */ function get() {
13774
+ if (this._isTextNoVisible()) {
13775
+ if (this._isContainDirtyFlag(0x8)) {
13776
+ var localBounds = this._localBounds;
13777
+ localBounds.min.set(0, 0, 0);
13778
+ localBounds.max.set(0, 0, 0);
13779
+ this._updateBounds(this._bounds);
13780
+ this._setDirtyFlagFalse(0x8);
13781
+ }
13782
+ return this._bounds;
13783
+ }
13745
13784
  this._isContainDirtyFlag(0x1) && this._resetSubFont();
13746
13785
  this._isContainDirtyFlag(0x2) && this._updateLocalData();
13747
13786
  this._isContainDirtyFlag(0x4) && this._updatePosition();
@@ -14763,6 +14802,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData1) {
14763
14802
  AssetType[/** Cube Compress Texture. */ "KTXCube"] = "KTXCube";
14764
14803
  AssetType[/** KTX2 Compress Texture */ "KTX2"] = "KTX2";
14765
14804
  AssetType[/** Sprite. */ "Sprite"] = "Sprite";
14805
+ AssetType[/** PrimitiveMesh. */ "PrimitiveMesh"] = "PrimitiveMesh";
14766
14806
  AssetType[/** Sprite Atlas. */ "SpriteAtlas"] = "SpriteAtlas";
14767
14807
  AssetType[/** Ambient light. */ "Env"] = "Environment";
14768
14808
  AssetType[/** Scene. */ "Scene"] = "Scene";
@@ -15148,6 +15188,7 @@ var /** @internal */ PromiseState;
15148
15188
  this./** The number of retries after failing to load assets. */ retryCount = 1;
15149
15189
  this./** Retry delay time after failed to load assets, in milliseconds. */ retryInterval = 0;
15150
15190
  this./** The default timeout period for loading assets, in milliseconds. */ timeout = Infinity;
15191
+ this./** Base url for loading assets. */ baseUrl = null;
15151
15192
  this._loadingPromises = {};
15152
15193
  this._assetPool = Object.create(null);
15153
15194
  this._assetUrlPool = Object.create(null);
@@ -15351,6 +15392,8 @@ var /** @internal */ PromiseState;
15351
15392
  // Check url mapping
15352
15393
  var itemURL = item.url;
15353
15394
  var url = this._virtualPathMap[itemURL] ? this._virtualPathMap[itemURL] : itemURL;
15395
+ // Not absolute and base url is set
15396
+ if (!Utils.isAbsoluteUrl(url) && this.baseUrl) url = Utils.resolveAbsoluteUrl(this.baseUrl, url);
15354
15397
  // Parse url
15355
15398
  var _this__parseURL = this._parseURL(url), assetBaseURL = _this__parseURL.assetBaseURL, queryPath = _this__parseURL.queryPath;
15356
15399
  var paths = queryPath ? this._parseQueryPath(queryPath) : [];
@@ -15443,10 +15486,20 @@ var /** @internal */ PromiseState;
15443
15486
  };
15444
15487
  _proto._parseURL = function _parseURL(path) {
15445
15488
  var _path_split = path.split("?"), baseUrl = _path_split[0], searchStr = _path_split[1];
15446
- var searchParams = new engineMiniprogramAdapter.URLSearchParams(searchStr);
15447
- var queryPath = searchParams.get("q");
15448
- searchParams.delete("q");
15449
- var assetBaseURL = searchParams.size > 0 ? baseUrl + "?" + searchParams.toString() : baseUrl;
15489
+ var queryPath = undefined;
15490
+ var assetBaseURL = baseUrl;
15491
+ if (searchStr) {
15492
+ var params = searchStr.split("&");
15493
+ for(var i = 0; i < params.length; i++){
15494
+ var param = params[i];
15495
+ if (param.startsWith("q=")) {
15496
+ queryPath = decodeURIComponent(param.split("=")[1]);
15497
+ params.splice(i, 1);
15498
+ break;
15499
+ }
15500
+ }
15501
+ assetBaseURL = params.length > 0 ? baseUrl + "?" + params.join("&") : baseUrl;
15502
+ }
15450
15503
  return {
15451
15504
  assetBaseURL: assetBaseURL,
15452
15505
  queryPath: queryPath
@@ -15730,6 +15783,66 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
15730
15783
  }
15731
15784
  }
15732
15785
  };
15786
+ /**
15787
+ * @internal
15788
+ */ SystemInfo._detectSIMDSupported = function _detectSIMDSupported() {
15789
+ if (this._simdSupported === null) {
15790
+ this._simdSupported = WebAssembly.validate(new Uint8Array([
15791
+ 0,
15792
+ 97,
15793
+ 115,
15794
+ 109,
15795
+ 1,
15796
+ 0,
15797
+ 0,
15798
+ 0,
15799
+ 1,
15800
+ 4,
15801
+ 1,
15802
+ 96,
15803
+ 0,
15804
+ 0,
15805
+ 3,
15806
+ 3,
15807
+ 2,
15808
+ 0,
15809
+ 0,
15810
+ 5,
15811
+ 3,
15812
+ 1,
15813
+ 0,
15814
+ 1,
15815
+ 12,
15816
+ 1,
15817
+ 0,
15818
+ 10,
15819
+ 22,
15820
+ 2,
15821
+ 12,
15822
+ 0,
15823
+ 65,
15824
+ 0,
15825
+ 65,
15826
+ 0,
15827
+ 65,
15828
+ 0,
15829
+ 252,
15830
+ 10,
15831
+ 0,
15832
+ 0,
15833
+ 11,
15834
+ 7,
15835
+ 0,
15836
+ 65,
15837
+ 0,
15838
+ 253,
15839
+ 15,
15840
+ 26,
15841
+ 11
15842
+ ]));
15843
+ }
15844
+ return this._simdSupported;
15845
+ };
15733
15846
  _create_class(SystemInfo, null, [
15734
15847
  {
15735
15848
  key: "devicePixelRatio",
@@ -15748,6 +15861,9 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
15748
15861
  (function() {
15749
15862
  /** The operating system is running on. */ SystemInfo.operatingSystem = "";
15750
15863
  })();
15864
+ (function() {
15865
+ /** Whether the system support SIMD. */ SystemInfo._simdSupported = null;
15866
+ })();
15751
15867
  SystemInfo._initialize();
15752
15868
 
15753
15869
  /**
@@ -15978,7 +16094,7 @@ SystemInfo._initialize();
15978
16094
  * Keyboard Manager.
15979
16095
  * @internal
15980
16096
  */ var KeyboardManager = /*#__PURE__*/ function() {
15981
- function KeyboardManager(engine) {
16097
+ function KeyboardManager(engine, target) {
15982
16098
  /** @internal */ this._curHeldDownKeyToIndexMap = [];
15983
16099
  /** @internal */ this._upKeyToFrameCountMap = [];
15984
16100
  /** @internal */ this._downKeyToFrameCountMap = [];
@@ -15986,17 +16102,11 @@ SystemInfo._initialize();
15986
16102
  /** @internal */ this._curFrameDownList = new DisorderedArray();
15987
16103
  /** @internal */ this._curFrameUpList = new DisorderedArray();
15988
16104
  this._nativeEvents = [];
15989
- this._hadListener = false;
15990
- // @ts-ignore
15991
- var htmlCanvas = engine._canvas._webCanvas;
15992
16105
  this._engine = engine;
15993
- this._htmlCanvas = htmlCanvas;
15994
- // Need to set tabIndex to make the canvas focus.
15995
- htmlCanvas.tabIndex = htmlCanvas.tabIndex;
16106
+ this._onBlur = this._onBlur.bind(this);
15996
16107
  this._onKeyEvent = this._onKeyEvent.bind(this);
15997
- htmlCanvas.addEventListener("keydown", this._onKeyEvent);
15998
- htmlCanvas.addEventListener("keyup", this._onKeyEvent);
15999
- this._hadListener = true;
16108
+ this._target = target;
16109
+ this._addEventListener();
16000
16110
  }
16001
16111
  var _proto = KeyboardManager.prototype;
16002
16112
  /**
@@ -16048,35 +16158,8 @@ SystemInfo._initialize();
16048
16158
  };
16049
16159
  /**
16050
16160
  * @internal
16051
- */ _proto._onFocus = function _onFocus() {
16052
- if (!this._hadListener) {
16053
- this._htmlCanvas.addEventListener("keydown", this._onKeyEvent);
16054
- this._htmlCanvas.addEventListener("keyup", this._onKeyEvent);
16055
- this._hadListener = true;
16056
- }
16057
- };
16058
- /**
16059
- * @internal
16060
- */ _proto._onBlur = function _onBlur() {
16061
- if (this._hadListener) {
16062
- this._htmlCanvas.removeEventListener("keydown", this._onKeyEvent);
16063
- this._htmlCanvas.removeEventListener("keyup", this._onKeyEvent);
16064
- this._curHeldDownKeyToIndexMap.length = 0;
16065
- this._curFrameHeldDownList.length = 0;
16066
- this._curFrameDownList.length = 0;
16067
- this._curFrameUpList.length = 0;
16068
- this._nativeEvents.length = 0;
16069
- this._hadListener = false;
16070
- }
16071
- };
16072
- /**
16073
- * @internal
16074
16161
  */ _proto._destroy = function _destroy() {
16075
- if (this._hadListener) {
16076
- this._htmlCanvas.removeEventListener("keydown", this._onKeyEvent);
16077
- this._htmlCanvas.removeEventListener("keyup", this._onKeyEvent);
16078
- this._hadListener = false;
16079
- }
16162
+ this._removeEventListener();
16080
16163
  this._curHeldDownKeyToIndexMap.length = 0;
16081
16164
  this._curHeldDownKeyToIndexMap = null;
16082
16165
  this._upKeyToFrameCountMap.length = 0;
@@ -16091,12 +16174,30 @@ SystemInfo._initialize();
16091
16174
  this._curFrameDownList = null;
16092
16175
  this._curFrameUpList.length = 0;
16093
16176
  this._curFrameUpList = null;
16094
- this._htmlCanvas = null;
16095
16177
  this._engine = null;
16096
16178
  };
16179
+ _proto._onBlur = function _onBlur() {
16180
+ this._curHeldDownKeyToIndexMap.length = 0;
16181
+ this._curFrameHeldDownList.length = 0;
16182
+ this._curFrameDownList.length = 0;
16183
+ this._curFrameUpList.length = 0;
16184
+ this._nativeEvents.length = 0;
16185
+ };
16097
16186
  _proto._onKeyEvent = function _onKeyEvent(evt) {
16098
16187
  this._nativeEvents.push(evt);
16099
16188
  };
16189
+ _proto._addEventListener = function _addEventListener() {
16190
+ var _this = this, target = _this._target;
16191
+ target.addEventListener("keydown", this._onKeyEvent);
16192
+ target.addEventListener("keyup", this._onKeyEvent);
16193
+ target.addEventListener("blur", this._onBlur);
16194
+ };
16195
+ _proto._removeEventListener = function _removeEventListener() {
16196
+ var _this = this, target = _this._target;
16197
+ target.removeEventListener("keydown", this._onKeyEvent);
16198
+ target.removeEventListener("keyup", this._onKeyEvent);
16199
+ target.removeEventListener("blur", this._onBlur);
16200
+ };
16100
16201
  return KeyboardManager;
16101
16202
  }();
16102
16203
 
@@ -16399,7 +16500,9 @@ var Collision = function Collision() {
16399
16500
  };
16400
16501
  if (hitResult != undefined) {
16401
16502
  var result = this._nativePhysicsScene.raycast(ray, distance, onRaycast, function(idx, distance, position, normal) {
16402
- hitResult.entity = _this._scene.engine._physicalObjectsMap[idx]._collider.entity;
16503
+ var hitShape = _this._scene.engine._physicalObjectsMap[idx];
16504
+ hitResult.entity = hitShape._collider.entity;
16505
+ hitResult.shape = hitShape;
16403
16506
  hitResult.distance = distance;
16404
16507
  hitResult.normal.copyFrom(normal);
16405
16508
  hitResult.point.copyFrom(position);
@@ -16408,6 +16511,7 @@ var Collision = function Collision() {
16408
16511
  return true;
16409
16512
  } else {
16410
16513
  hitResult.entity = null;
16514
+ hitResult.shape = null;
16411
16515
  hitResult.distance = 0;
16412
16516
  hitResult.point.set(0, 0, 0);
16413
16517
  hitResult.normal.set(0, 0, 0);
@@ -17069,6 +17173,7 @@ exports.DynamicColliderConstraints = void 0;
17069
17173
  /** The distance from the ray's origin to the impact point. */ this.distance = 0;
17070
17174
  /** The impact point in world space where the ray hit the collider. */ this.point = new miniprogram.Vector3();
17071
17175
  /** The normal of the surface the ray hit. */ this.normal = new miniprogram.Vector3();
17176
+ /** The shape of the collider that was hit. */ this.shape = null;
17072
17177
  };
17073
17178
 
17074
17179
  /**
@@ -18060,7 +18165,7 @@ __decorate([
18060
18165
  * Pointer Manager.
18061
18166
  * @internal
18062
18167
  */ var PointerManager = /*#__PURE__*/ function() {
18063
- function PointerManager(engine) {
18168
+ function PointerManager(engine, target) {
18064
18169
  /** @internal */ this._pointers = [];
18065
18170
  /** @internal */ this._multiPointerEnabled = true;
18066
18171
  /** @internal */ this._buttons = exports.PointerButton.None;
@@ -18069,16 +18174,18 @@ __decorate([
18069
18174
  /** @internal */ this._upList = new DisorderedArray();
18070
18175
  /** @internal */ this._downList = new DisorderedArray();
18071
18176
  this._nativeEvents = [];
18072
- this._hadListener = false;
18073
- // @ts-ignore
18074
- var htmlCanvas = engine._canvas._webCanvas;
18177
+ if (_instanceof(target, Window)) {
18178
+ throw "Do not set window as target because window cannot listen to pointer leave event.";
18179
+ }
18075
18180
  this._engine = engine;
18181
+ this._target = target;
18076
18182
  this._canvas = engine.canvas;
18077
- this._htmlCanvas = htmlCanvas;
18078
- this._onPointerEvent = this._onPointerEvent.bind(this);
18079
- this._onFocus();
18183
+ // @ts-ignore
18184
+ this._htmlCanvas = engine._canvas._webCanvas;
18080
18185
  // If there are no compatibility issues, navigator.maxTouchPoints should be used here
18081
18186
  this._pointerPool = new Array(11);
18187
+ this._onPointerEvent = this._onPointerEvent.bind(this);
18188
+ this._addEventListener();
18082
18189
  }
18083
18190
  var _proto = PointerManager.prototype;
18084
18191
  /**
@@ -18148,7 +18255,8 @@ __decorate([
18148
18255
  var length = events.length;
18149
18256
  if (length > 0) {
18150
18257
  for(var i1 = 0; i1 < length; i1++){
18151
- switch(events[i1].type){
18258
+ var event = events[i1];
18259
+ switch(event.type){
18152
18260
  case "pointerdown":
18153
18261
  pointer.phase = exports.PointerPhase.Down;
18154
18262
  pointer._firePointerDown(rayCastEntity);
@@ -18170,66 +18278,14 @@ __decorate([
18170
18278
  };
18171
18279
  /**
18172
18280
  * @internal
18173
- */ _proto._onFocus = function _onFocus() {
18174
- if (!this._hadListener) {
18175
- var _this = this, htmlCanvas = _this._htmlCanvas, onPointerEvent = _this._onPointerEvent;
18176
- htmlCanvas.addEventListener("pointerdown", onPointerEvent);
18177
- htmlCanvas.addEventListener("pointerup", onPointerEvent);
18178
- htmlCanvas.addEventListener("pointerleave", onPointerEvent);
18179
- htmlCanvas.addEventListener("pointermove", onPointerEvent);
18180
- htmlCanvas.addEventListener("pointercancel", onPointerEvent);
18181
- this._hadListener = true;
18182
- }
18183
- };
18184
- /**
18185
- * @internal
18186
- */ _proto._onBlur = function _onBlur() {
18187
- if (this._hadListener) {
18188
- var _this = this, htmlCanvas = _this._htmlCanvas, onPointerEvent = _this._onPointerEvent;
18189
- htmlCanvas.removeEventListener("pointerdown", onPointerEvent);
18190
- htmlCanvas.removeEventListener("pointerup", onPointerEvent);
18191
- htmlCanvas.removeEventListener("pointerleave", onPointerEvent);
18192
- htmlCanvas.removeEventListener("pointermove", onPointerEvent);
18193
- htmlCanvas.removeEventListener("pointercancel", onPointerEvent);
18194
- this._hadListener = false;
18195
- this._pointers.length = 0;
18196
- this._downList.length = 0;
18197
- this._upList.length = 0;
18198
- }
18199
- };
18200
- /**
18201
- * @internal
18202
18281
  */ _proto._destroy = function _destroy() {
18203
- // @ts-ignore
18204
- if (this._hadListener) {
18205
- var _this = this, htmlCanvas = _this._htmlCanvas, onPointerEvent = _this._onPointerEvent;
18206
- htmlCanvas.removeEventListener("pointerdown", onPointerEvent);
18207
- htmlCanvas.removeEventListener("pointerup", onPointerEvent);
18208
- htmlCanvas.removeEventListener("pointerleave", onPointerEvent);
18209
- htmlCanvas.removeEventListener("pointermove", onPointerEvent);
18210
- htmlCanvas.removeEventListener("pointercancel", onPointerEvent);
18211
- this._hadListener = false;
18212
- }
18282
+ this._removeEventListener();
18213
18283
  this._pointerPool.length = 0;
18214
- this._pointerPool = null;
18215
- this._pointers.length = 0;
18216
- this._pointers = null;
18217
- this._downList.length = 0;
18218
- this._downList = null;
18219
- this._upList.length = 0;
18220
- this._upList = null;
18221
18284
  this._nativeEvents.length = 0;
18222
- this._nativeEvents = null;
18223
- this._upMap.length = 0;
18224
- this._upMap = null;
18225
18285
  this._downMap.length = 0;
18226
- this._downMap = null;
18227
- this._htmlCanvas = null;
18228
- this._canvas = null;
18229
- this._engine = null;
18286
+ this._upMap.length = 0;
18230
18287
  };
18231
18288
  _proto._onPointerEvent = function _onPointerEvent(evt) {
18232
- evt.type === "pointerdown" && this._htmlCanvas.focus();
18233
18289
  this._nativeEvents.push(evt);
18234
18290
  };
18235
18291
  _proto._getPointerByID = function _getPointerByID(pointerId) {
@@ -18312,6 +18368,26 @@ __decorate([
18312
18368
  }
18313
18369
  return null;
18314
18370
  };
18371
+ _proto._addEventListener = function _addEventListener() {
18372
+ var _this = this, target = _this._target, onPointerEvent = _this._onPointerEvent;
18373
+ target.addEventListener("pointerdown", onPointerEvent);
18374
+ target.addEventListener("pointerup", onPointerEvent);
18375
+ target.addEventListener("pointerleave", onPointerEvent);
18376
+ target.addEventListener("pointermove", onPointerEvent);
18377
+ target.addEventListener("pointercancel", onPointerEvent);
18378
+ };
18379
+ _proto._removeEventListener = function _removeEventListener() {
18380
+ var _this = this, target = _this._target, onPointerEvent = _this._onPointerEvent;
18381
+ target.removeEventListener("pointerdown", onPointerEvent);
18382
+ target.removeEventListener("pointerup", onPointerEvent);
18383
+ target.removeEventListener("pointerleave", onPointerEvent);
18384
+ target.removeEventListener("pointermove", onPointerEvent);
18385
+ target.removeEventListener("pointercancel", onPointerEvent);
18386
+ this._nativeEvents.length = 0;
18387
+ this._pointers.length = 0;
18388
+ this._downList.length = 0;
18389
+ this._upList.length = 0;
18390
+ };
18315
18391
  return PointerManager;
18316
18392
  }();
18317
18393
  (function() {
@@ -18328,15 +18404,12 @@ __decorate([
18328
18404
  * Wheel Manager.
18329
18405
  * @internal
18330
18406
  */ var WheelManager = /*#__PURE__*/ function() {
18331
- function WheelManager(engine) {
18407
+ function WheelManager(engine, target) {
18332
18408
  /** @internal */ this._delta = new miniprogram.Vector3();
18333
18409
  this._nativeEvents = [];
18334
- // @ts-ignore
18335
- var htmlCanvas = engine._canvas._webCanvas;
18336
18410
  this._onWheelEvent = this._onWheelEvent.bind(this);
18337
- htmlCanvas.addEventListener("wheel", this._onWheelEvent);
18338
- this._canvas = htmlCanvas;
18339
- this._hadListener = true;
18411
+ this._target = target;
18412
+ this._addEventListener();
18340
18413
  }
18341
18414
  var _proto = WheelManager.prototype;
18342
18415
  /**
@@ -18357,35 +18430,24 @@ __decorate([
18357
18430
  };
18358
18431
  /**
18359
18432
  * @internal
18360
- */ _proto._onFocus = function _onFocus() {
18361
- if (!this._hadListener) {
18362
- this._canvas.addEventListener("wheel", this._onWheelEvent);
18363
- this._hadListener = true;
18364
- }
18433
+ */ _proto._addEventListener = function _addEventListener() {
18434
+ this._target.addEventListener("wheel", this._onWheelEvent);
18365
18435
  };
18366
18436
  /**
18367
18437
  * @internal
18368
- */ _proto._onBlur = function _onBlur() {
18369
- if (this._hadListener) {
18370
- this._canvas.removeEventListener("wheel", this._onWheelEvent);
18371
- this._nativeEvents.length = 0;
18372
- this._delta.set(0, 0, 0);
18373
- this._hadListener = false;
18374
- }
18438
+ */ _proto._removeEventListener = function _removeEventListener() {
18439
+ this._target.removeEventListener("wheel", this._onWheelEvent);
18440
+ this._nativeEvents.length = 0;
18441
+ this._delta.set(0, 0, 0);
18375
18442
  };
18376
18443
  /**
18377
18444
  * @internal
18378
18445
  */ _proto._destroy = function _destroy() {
18379
- if (this._hadListener) {
18380
- this._canvas.removeEventListener("wheel", this._onWheelEvent);
18381
- this._hadListener = false;
18382
- }
18446
+ this._removeEventListener();
18383
18447
  this._nativeEvents = null;
18384
- this._canvas = null;
18385
18448
  this._delta = null;
18386
18449
  };
18387
18450
  _proto._onWheelEvent = function _onWheelEvent(evt) {
18388
- evt.cancelable && evt.preventDefault();
18389
18451
  this._nativeEvents.push(evt);
18390
18452
  };
18391
18453
  return WheelManager;
@@ -18394,19 +18456,19 @@ __decorate([
18394
18456
  /**
18395
18457
  * InputManager manages device input such as mouse, touch, keyboard, etc.
18396
18458
  */ var InputManager = /*#__PURE__*/ function() {
18397
- function InputManager(engine) {
18459
+ function InputManager(engine, inputOptions) {
18398
18460
  /** Sometimes the input module will not be initialized, such as off-screen rendering. */ this._initialized = false;
18399
18461
  this._engine = engine;
18400
18462
  // @ts-ignore
18401
18463
  var canvas = engine._canvas._webCanvas;
18402
18464
  if (typeof engineMiniprogramAdapter.OffscreenCanvas === "undefined" || !_instanceof(canvas, engineMiniprogramAdapter.OffscreenCanvas)) {
18403
- this._wheelManager = new WheelManager(engine);
18404
- this._pointerManager = new PointerManager(engine);
18405
- this._keyboardManager = new KeyboardManager(engine);
18406
- this._onBlur = this._onBlur.bind(this);
18407
- engineMiniprogramAdapter.window.addEventListener("blur", this._onBlur);
18408
- this._onFocus = this._onFocus.bind(this);
18409
- engineMiniprogramAdapter.window.addEventListener("focus", this._onFocus);
18465
+ var _inputOptions, _inputOptions1, _inputOptions2;
18466
+ var _inputOptions_wheelTarget;
18467
+ this._wheelManager = new WheelManager(engine, (_inputOptions_wheelTarget = (_inputOptions = inputOptions) == null ? void 0 : _inputOptions.wheelTarget) != null ? _inputOptions_wheelTarget : canvas);
18468
+ var _inputOptions_pointerTarget;
18469
+ this._pointerManager = new PointerManager(engine, (_inputOptions_pointerTarget = (_inputOptions1 = inputOptions) == null ? void 0 : _inputOptions1.pointerTarget) != null ? _inputOptions_pointerTarget : canvas);
18470
+ var _inputOptions_keyboardTarget;
18471
+ this._keyboardManager = new KeyboardManager(engine, (_inputOptions_keyboardTarget = (_inputOptions2 = inputOptions) == null ? void 0 : _inputOptions2.keyboardTarget) != null ? _inputOptions_keyboardTarget : engineMiniprogramAdapter.window);
18410
18472
  this._initialized = true;
18411
18473
  }
18412
18474
  }
@@ -18519,8 +18581,6 @@ __decorate([
18519
18581
  * @internal
18520
18582
  */ _proto._destroy = function _destroy() {
18521
18583
  if (this._initialized) {
18522
- engineMiniprogramAdapter.window.removeEventListener("blur", this._onBlur);
18523
- engineMiniprogramAdapter.window.removeEventListener("focus", this._onFocus);
18524
18584
  this._wheelManager._destroy();
18525
18585
  this._wheelManager = null;
18526
18586
  this._pointerManager._destroy();
@@ -18529,16 +18589,6 @@ __decorate([
18529
18589
  this._keyboardManager = null;
18530
18590
  }
18531
18591
  };
18532
- _proto._onBlur = function _onBlur() {
18533
- this._wheelManager._onBlur();
18534
- this._pointerManager._onBlur();
18535
- this._keyboardManager._onBlur();
18536
- };
18537
- _proto._onFocus = function _onFocus() {
18538
- this._wheelManager._onFocus();
18539
- this._pointerManager._onFocus();
18540
- this._keyboardManager._onFocus();
18541
- };
18542
18592
  _create_class(InputManager, [
18543
18593
  {
18544
18594
  key: "pointers",
@@ -18581,6 +18631,8 @@ __decorate([
18581
18631
  _this = ReferResource1.call(this, engine) || this;
18582
18632
  /** @internal */ _this._renderStates = [] // todo: later will as a part of shaderData when shader effect frame is OK, that is more powerful and flexible.
18583
18633
  ;
18634
+ /** @internal */ _this._priority = 0 // todo: temporary resolution of submesh rendering order issue.
18635
+ ;
18584
18636
  _this._shaderData = new ShaderData(ShaderDataGroup.Material);
18585
18637
  _this.shader = shader;
18586
18638
  return _this;
@@ -18915,8 +18967,9 @@ var unlitVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#in
18915
18967
  }
18916
18968
  return;
18917
18969
  }
18970
+ ++hierarchy;
18918
18971
  for(var k1 in cacheMap){
18919
- this._recursiveDestroy(++hierarchy, cacheMap[k1]);
18972
+ this._recursiveDestroy(hierarchy, cacheMap[k1]);
18920
18973
  }
18921
18974
  };
18922
18975
  _proto._resizeCacheMapHierarchy = function _resizeCacheMapHierarchy(cacheMap, hierarchy, currentHierarchy, increaseHierarchy) {
@@ -19034,7 +19087,7 @@ ShaderPool.init();
19034
19087
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
19035
19088
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
19036
19089
  _this._textDefaultFont.isGCIgnored = true;
19037
- _this.inputManager = new InputManager(_assert_this_initialized(_this));
19090
+ _this.inputManager = new InputManager(_assert_this_initialized(_this), configuration.input);
19038
19091
  var xrDevice = configuration.xrDevice;
19039
19092
  if (xrDevice) {
19040
19093
  _this.xrManager = new XRManager();
@@ -19050,11 +19103,11 @@ ShaderPool.init();
19050
19103
  }
19051
19104
  var meshMagentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
19052
19105
  meshMagentaMaterial.isGCIgnored = true;
19053
- meshMagentaMaterial.shaderData.setColor("material_BaseColor", new Color(1.0, 0.0, 1.01, 1.0));
19106
+ meshMagentaMaterial.shaderData.setColor("material_BaseColor", new miniprogram.Color(1.0, 0.0, 1.01, 1.0));
19054
19107
  _this._meshMagentaMaterial = meshMagentaMaterial;
19055
19108
  var particleMagentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("particle-shader"));
19056
19109
  particleMagentaMaterial.isGCIgnored = true;
19057
- particleMagentaMaterial.shaderData.setColor("material_BaseColor", new Color(1.0, 0.0, 1.01, 1.0));
19110
+ particleMagentaMaterial.shaderData.setColor("material_BaseColor", new miniprogram.Color(1.0, 0.0, 1.01, 1.0));
19058
19111
  _this._particleMagentaMaterial = particleMagentaMaterial;
19059
19112
  var innerSettings = _this._settings;
19060
19113
  var colorSpace = configuration.colorSpace || exports.ColorSpace.Linear;
@@ -19328,6 +19381,26 @@ ShaderPool.init();
19328
19381
  this._magentaTexture2D = magentaTexture2D;
19329
19382
  this._magentaTextureCube = magentaTextureCube;
19330
19383
  if (hardwareRenderer.isWebGL2) {
19384
+ var magentaPixel32 = new Uint32Array([
19385
+ 255,
19386
+ 0,
19387
+ 255,
19388
+ 255
19389
+ ]);
19390
+ var uintMagentaTexture2D = new Texture2D(this, 1, 1, exports.TextureFormat.R32G32B32A32_UInt, false);
19391
+ uintMagentaTexture2D.setPixelBuffer(magentaPixel32);
19392
+ uintMagentaTexture2D.isGCIgnored = true;
19393
+ this.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
19394
+ _inherits(_class, ContentRestorer);
19395
+ function _class() {
19396
+ return ContentRestorer.call(this, uintMagentaTexture2D);
19397
+ }
19398
+ var _proto = _class.prototype;
19399
+ _proto.restoreContent = function restoreContent() {
19400
+ this.resource.setPixelBuffer(magentaPixel32);
19401
+ };
19402
+ return _class;
19403
+ }(ContentRestorer))());
19331
19404
  var magentaTexture2DArray = new Texture2DArray(this, 1, 1, 1, exports.TextureFormat.R8G8B8A8, false);
19332
19405
  magentaTexture2DArray.setPixelBuffer(0, magentaPixel);
19333
19406
  magentaTexture2DArray.isGCIgnored = true;
@@ -19342,6 +19415,7 @@ ShaderPool.init();
19342
19415
  };
19343
19416
  return _class;
19344
19417
  }(ContentRestorer))());
19418
+ this._uintMagentaTexture2D = uintMagentaTexture2D;
19345
19419
  this._magentaTexture2DArray = magentaTexture2DArray;
19346
19420
  }
19347
19421
  };
@@ -19574,8 +19648,8 @@ ShaderPool.init();
19574
19648
  set: function set(value) {
19575
19649
  if (this._width !== value) {
19576
19650
  this._width = value;
19651
+ this._onWidthChanged(value);
19577
19652
  this._sizeUpdateFlagManager.dispatch();
19578
- this._onSizeChanged(value, this._width);
19579
19653
  }
19580
19654
  }
19581
19655
  },
@@ -19589,8 +19663,8 @@ ShaderPool.init();
19589
19663
  set: function set(value) {
19590
19664
  if (this._height !== value) {
19591
19665
  this._height = value;
19666
+ this._onHeightChange(value);
19592
19667
  this._sizeUpdateFlagManager.dispatch();
19593
- this._onSizeChanged(this._width, value);
19594
19668
  }
19595
19669
  }
19596
19670
  }
@@ -20945,6 +21019,10 @@ __decorate([
20945
21019
  /** The splits of two cascade distribution. */ _this.shadowTwoCascadeSplits = 1.0 / 3.0;
20946
21020
  /** The splits of four cascade distribution. */ _this.shadowFourCascadeSplits = new miniprogram.Vector3(1.0 / 15, 3.0 / 15.0, 7.0 / 15.0);
20947
21021
  /** Max Shadow distance. */ _this.shadowDistance = 50;
21022
+ /**
21023
+ * Last shadow fade distance in percentage, range [0,1].
21024
+ * @remarks Value 0 is used for no shadow fade.
21025
+ */ _this.shadowFadeBorder = 0.1;
20948
21026
  /* @internal */ _this._lightManager = new LightManager();
20949
21027
  /* @internal */ _this._componentsManager = new ComponentsManager();
20950
21028
  /** @internal */ _this._isActiveInEngine = false;
@@ -21569,47 +21647,66 @@ __decorate([
21569
21647
  DepthTextureMode[DepthTextureMode[/* Generate depth texture by pre-pass rendering. */ "PrePass"] = 1] = "PrePass";
21570
21648
  })(exports.DepthTextureMode || (exports.DepthTextureMode = {}));
21571
21649
 
21572
- var passNum = 0;
21573
21650
  /**
21574
- * RenderPass.
21575
- */ var RenderPass = /*#__PURE__*/ function() {
21576
- function RenderPass(name, priority, renderTarget, replaceMaterial, mask) {
21577
- if (name === void 0) name = "RENDER_PASS" + passNum++;
21578
- if (priority === void 0) priority = 0;
21579
- if (renderTarget === void 0) renderTarget = null;
21580
- if (replaceMaterial === void 0) replaceMaterial = null;
21581
- if (mask === void 0) mask = null;
21582
- this.name = name;
21583
- this.enabled = true;
21584
- this.priority = priority;
21585
- this.renderTarget = renderTarget;
21586
- this.replaceMaterial = replaceMaterial;
21587
- this.mask = mask || exports.Layer.Everything;
21588
- this.renderOverride = false; // If renderOverride is set to true, you need to implement the render method
21589
- }
21590
- var _proto = RenderPass.prototype;
21591
- /**
21592
- * Rendering callback, will be executed if renderOverride is set to true.
21593
- * @param camera - Camera
21594
- * @param opaqueQueue - Opaque queue
21595
- * @param alphaTestQueue - Alpha test queue
21596
- * @param transparentQueue - Transparent queue
21597
- */ _proto.render = function render(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21651
+ * PipelinePass is a base class for all pipeline passes.
21652
+ */ var PipelinePass = function PipelinePass(engine) {
21653
+ this._engine = engine;
21654
+ };
21655
+
21656
+ /**
21657
+ * @internal
21658
+ */ var PipelineUtils = /*#__PURE__*/ function() {
21659
+ function PipelineUtils() {}
21598
21660
  /**
21599
- * Post rendering callback.
21600
- * @param camera - Camera
21601
- * @param opaqueQueue - Opaque queue
21602
- * @param alphaTestQueue - Alpha test queue
21603
- * @param transparentQueue - Transparent queue
21604
- */ _proto.preRender = function preRender(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21661
+ * Recreate texture if needed.
21662
+ * @param engine - Engine
21663
+ * @param currentTexture - Current texture
21664
+ * @param width - Need texture width
21665
+ * @param height - Need texture height
21666
+ * @param format - Need texture format
21667
+ * @param mipmap - Need texture mipmap
21668
+ * @returns Texture
21669
+ */ PipelineUtils.recreateTextureIfNeeded = function recreateTextureIfNeeded(engine, currentTexture, width, height, format, mipmap) {
21670
+ if (currentTexture) {
21671
+ if (currentTexture.width !== width || currentTexture.height !== height || currentTexture.format !== format || currentTexture.mipmapCount > 1 !== mipmap) {
21672
+ currentTexture.destroy();
21673
+ var texture = new Texture2D(engine, width, height, format, mipmap);
21674
+ texture.isGCIgnored = true;
21675
+ return texture;
21676
+ } else {
21677
+ return currentTexture;
21678
+ }
21679
+ } else {
21680
+ var texture1 = new Texture2D(engine, width, height, format, mipmap);
21681
+ texture1.isGCIgnored = true;
21682
+ return texture1;
21683
+ }
21684
+ };
21605
21685
  /**
21606
- * Post rendering callback.
21607
- * @param camera - Camera
21608
- * @param opaqueQueue - Opaque queue
21609
- * @param alphaTestQueue - Alpha test queue
21610
- * @param transparentQueue - Transparent queue
21611
- */ _proto.postRender = function postRender(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21612
- return RenderPass;
21686
+ * Recreate render target if needed.
21687
+ * @param engine - Engine
21688
+ * @param currentRenderTarget - Current render target
21689
+ * @param width - Need render target width
21690
+ * @param height - Need render target height
21691
+ * @param colorFormat - Need render target color format
21692
+ * @param depthFormat - Need render target depth format
21693
+ * @param mipmap - Need render target mipmap
21694
+ * @returns Render target
21695
+ */ PipelineUtils.recreateRenderTargetIfNeeded = function recreateRenderTargetIfNeeded(engine, currentRenderTarget, width, height, colorFormat, depthFormat, mipmap) {
21696
+ var _currentRenderTarget, _currentRenderTarget1;
21697
+ var currentColorTexture = (_currentRenderTarget = currentRenderTarget) == null ? void 0 : _currentRenderTarget.getColorTexture(0);
21698
+ var currentDepthTexture = (_currentRenderTarget1 = currentRenderTarget) == null ? void 0 : _currentRenderTarget1.depthTexture;
21699
+ var colorTexture = colorFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentColorTexture, width, height, colorFormat, mipmap) : null;
21700
+ var depthTexture = depthFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentDepthTexture, width, height, depthFormat, mipmap) : null;
21701
+ if (currentColorTexture !== colorTexture || currentDepthTexture !== depthTexture) {
21702
+ var _currentRenderTarget2;
21703
+ (_currentRenderTarget2 = currentRenderTarget) == null ? void 0 : _currentRenderTarget2.destroy();
21704
+ currentRenderTarget = new RenderTarget(engine, width, height, colorTexture, depthTexture);
21705
+ currentRenderTarget.isGCIgnored = true;
21706
+ }
21707
+ return currentRenderTarget;
21708
+ };
21709
+ return PipelineUtils;
21613
21710
  }();
21614
21711
 
21615
21712
  /**
@@ -21870,70 +21967,93 @@ var passNum = 0;
21870
21967
  /**
21871
21968
  * @internal
21872
21969
  */ RenderQueue._compareFromNearToFar = function _compareFromNearToFar(a, b) {
21873
- return a.data.component.priority - b.data.component.priority || a.data.component._distanceForSort - b.data.component._distanceForSort;
21970
+ var dataA = a.data;
21971
+ var dataB = b.data;
21972
+ var componentA = dataA.component;
21973
+ var componentB = dataB.component;
21974
+ var priorityOrder = componentA.priority - componentB.priority;
21975
+ if (priorityOrder !== 0) {
21976
+ return priorityOrder;
21977
+ }
21978
+ // make suer from the same renderer.
21979
+ if (componentA.instanceId === componentB.instanceId) {
21980
+ return dataA.material._priority - dataB.material._priority;
21981
+ } else {
21982
+ var distanceDiff = componentA._distanceForSort - componentB._distanceForSort;
21983
+ if (distanceDiff === 0) {
21984
+ return componentA.instanceId - componentB.instanceId;
21985
+ } else {
21986
+ return distanceDiff;
21987
+ }
21988
+ }
21874
21989
  };
21875
21990
  /**
21876
21991
  * @internal
21877
21992
  */ RenderQueue._compareFromFarToNear = function _compareFromFarToNear(a, b) {
21878
- return a.data.component.priority - b.data.component.priority || b.data.component._distanceForSort - a.data.component._distanceForSort;
21993
+ var dataA = a.data;
21994
+ var dataB = b.data;
21995
+ var componentA = dataA.component;
21996
+ var componentB = dataB.component;
21997
+ var priorityOrder = componentA.priority - componentB.priority;
21998
+ if (priorityOrder !== 0) {
21999
+ return priorityOrder;
22000
+ }
22001
+ // make suer from the same renderer.
22002
+ if (componentA.instanceId === componentB.instanceId) {
22003
+ return dataA.material._priority - dataB.material._priority;
22004
+ } else {
22005
+ var distanceDiff = componentB._distanceForSort - componentA._distanceForSort;
22006
+ if (distanceDiff === 0) {
22007
+ return componentA.instanceId - componentB.instanceId;
22008
+ } else {
22009
+ return distanceDiff;
22010
+ }
22011
+ }
21879
22012
  };
21880
22013
  return RenderQueue;
21881
22014
  }();
21882
22015
 
22016
+ var passNum = 0;
21883
22017
  /**
21884
- * @internal
21885
- */ var PipelineUtils = /*#__PURE__*/ function() {
21886
- function PipelineUtils() {}
22018
+ * RenderPass.
22019
+ */ var RenderPass = /*#__PURE__*/ function() {
22020
+ function RenderPass(name, priority, renderTarget, replaceMaterial, mask) {
22021
+ if (name === void 0) name = "RENDER_PASS" + passNum++;
22022
+ if (priority === void 0) priority = 0;
22023
+ if (renderTarget === void 0) renderTarget = null;
22024
+ if (replaceMaterial === void 0) replaceMaterial = null;
22025
+ if (mask === void 0) mask = null;
22026
+ this.name = name;
22027
+ this.enabled = true;
22028
+ this.priority = priority;
22029
+ this.renderTarget = renderTarget;
22030
+ this.replaceMaterial = replaceMaterial;
22031
+ this.mask = mask || exports.Layer.Everything;
22032
+ this.renderOverride = false; // If renderOverride is set to true, you need to implement the render method
22033
+ }
22034
+ var _proto = RenderPass.prototype;
21887
22035
  /**
21888
- * Recreate texture if needed.
21889
- * @param engine - Engine
21890
- * @param currentTexture - Current texture
21891
- * @param width - Need texture width
21892
- * @param height - Need texture height
21893
- * @param format - Need texture format
21894
- * @param mipmap - Need texture mipmap
21895
- * @returns Texture
21896
- */ PipelineUtils.recreateTextureIfNeeded = function recreateTextureIfNeeded(engine, currentTexture, width, height, format, mipmap) {
21897
- if (currentTexture) {
21898
- if (currentTexture.width !== width || currentTexture.height !== height || currentTexture.format !== format || currentTexture.mipmapCount > 1 !== mipmap) {
21899
- currentTexture.destroy();
21900
- var texture = new Texture2D(engine, width, height, format, mipmap);
21901
- texture.isGCIgnored = true;
21902
- return texture;
21903
- } else {
21904
- return currentTexture;
21905
- }
21906
- } else {
21907
- var texture1 = new Texture2D(engine, width, height, format, mipmap);
21908
- texture1.isGCIgnored = true;
21909
- return texture1;
21910
- }
21911
- };
22036
+ * Rendering callback, will be executed if renderOverride is set to true.
22037
+ * @param camera - Camera
22038
+ * @param opaqueQueue - Opaque queue
22039
+ * @param alphaTestQueue - Alpha test queue
22040
+ * @param transparentQueue - Transparent queue
22041
+ */ _proto.render = function render(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
21912
22042
  /**
21913
- * Recreate render target if needed.
21914
- * @param engine - Engine
21915
- * @param currentRenderTarget - Current render target
21916
- * @param width - Need render target width
21917
- * @param height - Need render target height
21918
- * @param colorFormat - Need render target color format
21919
- * @param depthFormat - Need render target depth format
21920
- * @param mipmap - Need render target mipmap
21921
- * @returns Render target
21922
- */ PipelineUtils.recreateRenderTargetIfNeeded = function recreateRenderTargetIfNeeded(engine, currentRenderTarget, width, height, colorFormat, depthFormat, mipmap) {
21923
- var _currentRenderTarget, _currentRenderTarget1;
21924
- var currentColorTexture = (_currentRenderTarget = currentRenderTarget) == null ? void 0 : _currentRenderTarget.getColorTexture(0);
21925
- var currentDepthTexture = (_currentRenderTarget1 = currentRenderTarget) == null ? void 0 : _currentRenderTarget1.depthTexture;
21926
- var colorTexture = colorFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentColorTexture, width, height, colorFormat, mipmap) : null;
21927
- var depthTexture = depthFormat ? PipelineUtils.recreateTextureIfNeeded(engine, currentDepthTexture, width, height, depthFormat, mipmap) : null;
21928
- if (currentColorTexture !== colorTexture || currentDepthTexture !== depthTexture) {
21929
- var _currentRenderTarget2;
21930
- (_currentRenderTarget2 = currentRenderTarget) == null ? void 0 : _currentRenderTarget2.destroy();
21931
- currentRenderTarget = new RenderTarget(engine, width, height, colorTexture, depthTexture);
21932
- currentRenderTarget.isGCIgnored = true;
21933
- }
21934
- return currentRenderTarget;
21935
- };
21936
- return PipelineUtils;
22043
+ * Post rendering callback.
22044
+ * @param camera - Camera
22045
+ * @param opaqueQueue - Opaque queue
22046
+ * @param alphaTestQueue - Alpha test queue
22047
+ * @param transparentQueue - Transparent queue
22048
+ */ _proto.preRender = function preRender(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
22049
+ /**
22050
+ * Post rendering callback.
22051
+ * @param camera - Camera
22052
+ * @param opaqueQueue - Opaque queue
22053
+ * @param alphaTestQueue - Alpha test queue
22054
+ * @param transparentQueue - Transparent queue
22055
+ */ _proto.postRender = function postRender(camera, opaqueQueue, alphaTestQueue, transparentQueue) {};
22056
+ return RenderPass;
21937
22057
  }();
21938
22058
 
21939
22059
  /**
@@ -22201,6 +22321,26 @@ var /**
22201
22321
  var offset = cascadeIndex * 16;
22202
22322
  Utils._floatMatrixMultiply(sliceMatrix, outShadowMatrices, offset, outShadowMatrices, offset);
22203
22323
  };
22324
+ /**
22325
+ * Extract scale and bias from a fade distance to achieve a linear fading of the fade distance.
22326
+ */ ShadowUtils.getScaleAndBiasForLinearDistanceFade = function getScaleAndBiasForLinearDistanceFade(fadeDistance, border, outInfo) {
22327
+ // (P^2-N^2)/(F^2-N^2)
22328
+ // To avoid division from zero
22329
+ // This values ensure that fade within cascade will be 0 and outside 1
22330
+ if (border < 0.0001) {
22331
+ var multiplier = 1000; // To avoid blending if difference is in fractions
22332
+ outInfo.z = multiplier;
22333
+ outInfo.w = -fadeDistance * multiplier;
22334
+ return;
22335
+ }
22336
+ border = 1 - border;
22337
+ border *= border;
22338
+ // Fade with distance calculation is just a linear fade from 90% of fade distance to fade distance. 90% arbitrarily chosen but should work well enough.
22339
+ var distanceFadeNear = border * fadeDistance;
22340
+ var fadeRange = fadeDistance - distanceFadeNear;
22341
+ outInfo.z = 1.0 / fadeRange;
22342
+ outInfo.w = -distanceFadeNear / fadeRange;
22343
+ };
22204
22344
  return ShadowUtils;
22205
22345
  }();
22206
22346
  (function() {
@@ -22445,12 +22585,6 @@ var /**
22445
22585
  ShadowUtils.atlasBorderSize = 4.0;
22446
22586
  })();
22447
22587
 
22448
- /**
22449
- * PipelinePass is a base class for all pipeline passes.
22450
- */ var PipelinePass = function PipelinePass(engine) {
22451
- this._engine = engine;
22452
- };
22453
-
22454
22588
  /**
22455
22589
  * Cascade shadow caster pass.
22456
22590
  */ var CascadedShadowCasterPass = /*#__PURE__*/ function(PipelinePass1) {
@@ -22463,11 +22597,10 @@ var /**
22463
22597
  _this._shadowSliceData = new ShadowSliceData();
22464
22598
  _this._lightUp = new miniprogram.Vector3();
22465
22599
  _this._lightSide = new miniprogram.Vector3();
22466
- _this._existShadowMap = false;
22467
22600
  _this._splitBoundSpheres = new Float32Array(CascadedShadowCasterPass._maxCascades * 4);
22468
22601
  /** The end is project precision problem in shader. */ _this._shadowMatrices = new Float32Array((CascadedShadowCasterPass._maxCascades + 1) * 16);
22469
- // strength, null, lightIndex
22470
- _this._shadowInfos = new miniprogram.Vector3();
22602
+ // intensity, null, fadeScale, fadeBias
22603
+ _this._shadowInfos = new miniprogram.Vector4();
22471
22604
  _this._viewportOffsets = [
22472
22605
  new miniprogram.Vector2(),
22473
22606
  new miniprogram.Vector2(),
@@ -22483,14 +22616,12 @@ var /**
22483
22616
  /**
22484
22617
  * @internal
22485
22618
  */ _proto.onRender = function onRender(context) {
22619
+ var light = this._camera.scene._lightManager._sunlight;
22486
22620
  this._updateShadowSettings();
22487
- this._existShadowMap = false;
22488
- this._renderDirectShadowMap(context);
22489
- if (this._existShadowMap) {
22490
- this._updateReceiversShaderData();
22491
- }
22621
+ this._renderDirectShadowMap(context, light);
22622
+ this._updateReceiversShaderData(light);
22492
22623
  };
22493
- _proto._renderDirectShadowMap = function _renderDirectShadowMap(context) {
22624
+ _proto._renderDirectShadowMap = function _renderDirectShadowMap(context, light) {
22494
22625
  var _this = this, engine = _this._engine, camera = _this._camera, viewports = _this._viewportOffsets, shadowSliceData = _this._shadowSliceData, splitBoundSpheres = _this._splitBoundSpheres, shadowMatrices = _this._shadowMatrices;
22495
22626
  var _camera__renderPipeline__cullingResults = camera._renderPipeline._cullingResults, opaqueQueue = _camera__renderPipeline__cullingResults.opaqueQueue, alphaTestQueue = _camera__renderPipeline__cullingResults.alphaTestQueue, transparentQueue = _camera__renderPipeline__cullingResults.transparentQueue;
22496
22627
  var scene = camera.scene;
@@ -22504,91 +22635,87 @@ var /**
22504
22635
  var lightUp = this._lightUp;
22505
22636
  var lightSide = this._lightSide;
22506
22637
  var lightForward = shadowSliceData.virtualCamera.forward;
22507
- var light = scene._lightManager._sunlight;
22508
- if (light) {
22509
- var shadowFar = Math.min(camera.scene.shadowDistance, camera.farClipPlane);
22510
- this._getCascadesSplitDistance(shadowFar);
22511
- // Prepare render target
22512
- var _this__shadowMapSize = this._shadowMapSize, width = _this__shadowMapSize.z, height = _this__shadowMapSize.w;
22513
- var format = this._shadowMapFormat;
22514
- var renderTarget;
22515
- var shadowTexture;
22516
- if (this._supportDepthTexture) {
22517
- renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, null, format, false);
22518
- shadowTexture = renderTarget.depthTexture;
22519
- } else {
22520
- renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, format, null, false);
22521
- shadowTexture = renderTarget.getColorTexture(0);
22522
- }
22523
- shadowTexture.wrapModeU = shadowTexture.wrapModeV = exports.TextureWrapMode.Clamp;
22524
- if (engine._hardwareRenderer._isWebGL2) {
22525
- shadowTexture.depthCompareFunction = exports.TextureDepthCompareFunction.Less;
22526
- }
22527
- this._renderTarget = renderTarget;
22528
- this._depthTexture = shadowTexture;
22529
- // @todo: shouldn't set viewport and scissor in activeRenderTarget
22530
- rhi.activeRenderTarget(renderTarget, CascadedShadowCasterPass._viewport, 0);
22531
- if (this._supportDepthTexture) {
22532
- rhi.clearRenderTarget(engine, exports.CameraClearFlags.Depth, null);
22533
- } else {
22534
- rhi.clearRenderTarget(engine, exports.CameraClearFlags.All, CascadedShadowCasterPass._clearColor);
22535
- }
22536
- this._shadowInfos.x = light.shadowStrength;
22537
- this._shadowInfos.z = 0; // @todo: sun light index always 0
22538
- // prepare light and camera direction
22539
- miniprogram.Matrix.rotationQuaternion(light.entity.transform.worldRotationQuaternion, lightWorld);
22540
- lightSide.set(lightWorldE[0], lightWorldE[1], lightWorldE[2]);
22541
- lightUp.set(lightWorldE[4], lightWorldE[5], lightWorldE[6]);
22542
- lightForward.set(-lightWorldE[8], -lightWorldE[9], -lightWorldE[10]);
22543
- var cameraForward = CascadedShadowCasterPass._tempVector;
22544
- cameraForward.copyFrom(camera.entity.transform.worldForward);
22545
- var shadowTileResolution = this._shadowTileResolution;
22546
- for(var j = 0; j < shadowCascades; j++){
22547
- ShadowUtils.getBoundSphereByFrustum(splitDistance[j], splitDistance[j + 1], camera, cameraForward, shadowSliceData);
22548
- ShadowUtils.getDirectionLightShadowCullPlanes(camera._frustum, splitDistance[j], camera.nearClipPlane, lightForward, shadowSliceData);
22549
- ShadowUtils.getDirectionalLightMatrices(lightUp, lightSide, lightForward, j, light.shadowNearPlane, shadowTileResolution, shadowSliceData, shadowMatrices);
22550
- if (shadowCascades > 1) {
22551
- ShadowUtils.applySliceTransform(shadowTileResolution, width, height, j, this._viewportOffsets[j], shadowMatrices);
22552
- }
22553
- this._updateSingleShadowCasterShaderData(light, shadowSliceData, context);
22554
- // upload pre-cascade infos.
22555
- var center = boundSphere.center;
22556
- var radius = boundSphere.radius;
22557
- var offset = j * 4;
22558
- splitBoundSpheres[offset] = center.x;
22559
- splitBoundSpheres[offset + 1] = center.y;
22560
- splitBoundSpheres[offset + 2] = center.z;
22561
- splitBoundSpheres[offset + 3] = radius * radius;
22562
- opaqueQueue.clear();
22563
- alphaTestQueue.clear();
22564
- transparentQueue.clear();
22565
- var renderers = componentsManager._renderers;
22566
- var elements = renderers._elements;
22567
- for(var k = renderers.length - 1; k >= 0; --k){
22568
- ShadowUtils.shadowCullFrustum(context, light, elements[k], shadowSliceData);
22569
- }
22570
- if (opaqueQueue.elements.length || alphaTestQueue.elements.length) {
22571
- opaqueQueue.sort(RenderQueue._compareFromNearToFar);
22572
- alphaTestQueue.sort(RenderQueue._compareFromNearToFar);
22573
- var _viewports_j = viewports[j], x = _viewports_j.x, y = _viewports_j.y;
22574
- rhi.setGlobalDepthBias(1.0, 1.0);
22575
- rhi.viewport(x, y, shadowTileResolution, shadowTileResolution);
22576
- // for no cascade is for the edge,for cascade is for the beyond maxCascade pixel can use (0,0,0) trick sample the shadowMap
22577
- rhi.scissor(x + 1, y + 1, shadowTileResolution - 2, shadowTileResolution - 2);
22578
- engine._renderCount++;
22579
- opaqueQueue.render(camera, exports.Layer.Everything, exports.PipelineStage.ShadowCaster);
22580
- alphaTestQueue.render(camera, exports.Layer.Everything, exports.PipelineStage.ShadowCaster);
22581
- rhi.setGlobalDepthBias(0, 0);
22582
- }
22583
- }
22584
- this._existShadowMap = true;
22585
- }
22586
- };
22587
- _proto._updateReceiversShaderData = function _updateReceiversShaderData() {
22588
- var scene = this._camera.scene;
22638
+ // Prepare render target
22639
+ var _this__shadowMapSize = this._shadowMapSize, width = _this__shadowMapSize.z, height = _this__shadowMapSize.w;
22640
+ var format = this._shadowMapFormat;
22641
+ var renderTarget;
22642
+ var shadowTexture;
22643
+ if (this._supportDepthTexture) {
22644
+ renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, null, format, false);
22645
+ shadowTexture = renderTarget.depthTexture;
22646
+ } else {
22647
+ renderTarget = PipelineUtils.recreateRenderTargetIfNeeded(engine, this._renderTarget, width, height, format, null, false);
22648
+ shadowTexture = renderTarget.getColorTexture(0);
22649
+ }
22650
+ shadowTexture.wrapModeU = shadowTexture.wrapModeV = exports.TextureWrapMode.Clamp;
22651
+ if (engine._hardwareRenderer._isWebGL2) {
22652
+ shadowTexture.depthCompareFunction = exports.TextureDepthCompareFunction.Less;
22653
+ }
22654
+ this._renderTarget = renderTarget;
22655
+ this._depthTexture = shadowTexture;
22656
+ // @todo: shouldn't set viewport and scissor in activeRenderTarget
22657
+ rhi.activeRenderTarget(renderTarget, CascadedShadowCasterPass._viewport, 0);
22658
+ if (this._supportDepthTexture) {
22659
+ rhi.clearRenderTarget(engine, exports.CameraClearFlags.Depth, null);
22660
+ } else {
22661
+ rhi.clearRenderTarget(engine, exports.CameraClearFlags.All, CascadedShadowCasterPass._clearColor);
22662
+ }
22663
+ // prepare light and camera direction
22664
+ miniprogram.Matrix.rotationQuaternion(light.entity.transform.worldRotationQuaternion, lightWorld);
22665
+ lightSide.set(lightWorldE[0], lightWorldE[1], lightWorldE[2]);
22666
+ lightUp.set(lightWorldE[4], lightWorldE[5], lightWorldE[6]);
22667
+ lightForward.set(-lightWorldE[8], -lightWorldE[9], -lightWorldE[10]);
22668
+ var cameraForward = CascadedShadowCasterPass._tempVector;
22669
+ cameraForward.copyFrom(camera.entity.transform.worldForward);
22670
+ var shadowTileResolution = this._shadowTileResolution;
22671
+ for(var j = 0; j < shadowCascades; j++){
22672
+ ShadowUtils.getBoundSphereByFrustum(splitDistance[j], splitDistance[j + 1], camera, cameraForward, shadowSliceData);
22673
+ ShadowUtils.getDirectionLightShadowCullPlanes(camera._frustum, splitDistance[j], camera.nearClipPlane, lightForward, shadowSliceData);
22674
+ ShadowUtils.getDirectionalLightMatrices(lightUp, lightSide, lightForward, j, light.shadowNearPlane, shadowTileResolution, shadowSliceData, shadowMatrices);
22675
+ if (shadowCascades > 1) {
22676
+ ShadowUtils.applySliceTransform(shadowTileResolution, width, height, j, this._viewportOffsets[j], shadowMatrices);
22677
+ }
22678
+ this._updateSingleShadowCasterShaderData(light, shadowSliceData, context);
22679
+ // upload pre-cascade infos.
22680
+ var center = boundSphere.center;
22681
+ var radius = boundSphere.radius;
22682
+ var offset = j * 4;
22683
+ splitBoundSpheres[offset] = center.x;
22684
+ splitBoundSpheres[offset + 1] = center.y;
22685
+ splitBoundSpheres[offset + 2] = center.z;
22686
+ splitBoundSpheres[offset + 3] = radius * radius;
22687
+ opaqueQueue.clear();
22688
+ alphaTestQueue.clear();
22689
+ transparentQueue.clear();
22690
+ var renderers = componentsManager._renderers;
22691
+ var elements = renderers._elements;
22692
+ for(var k = renderers.length - 1; k >= 0; --k){
22693
+ ShadowUtils.shadowCullFrustum(context, light, elements[k], shadowSliceData);
22694
+ }
22695
+ if (opaqueQueue.elements.length || alphaTestQueue.elements.length) {
22696
+ opaqueQueue.sort(RenderQueue._compareFromNearToFar);
22697
+ alphaTestQueue.sort(RenderQueue._compareFromNearToFar);
22698
+ var _viewports_j = viewports[j], x = _viewports_j.x, y = _viewports_j.y;
22699
+ rhi.setGlobalDepthBias(1.0, 1.0);
22700
+ rhi.viewport(x, y, shadowTileResolution, shadowTileResolution);
22701
+ // for no cascade is for the edge,for cascade is for the beyond maxCascade pixel can use (0,0,0) trick sample the shadowMap
22702
+ rhi.scissor(x + 1, y + 1, shadowTileResolution - 2, shadowTileResolution - 2);
22703
+ engine._renderCount++;
22704
+ opaqueQueue.render(camera, exports.Layer.Everything, exports.PipelineStage.ShadowCaster);
22705
+ alphaTestQueue.render(camera, exports.Layer.Everything, exports.PipelineStage.ShadowCaster);
22706
+ rhi.setGlobalDepthBias(0, 0);
22707
+ }
22708
+ }
22709
+ };
22710
+ _proto._updateReceiversShaderData = function _updateReceiversShaderData(light) {
22711
+ var camera = this._camera;
22712
+ var scene = camera.scene;
22589
22713
  var splitBoundSpheres = this._splitBoundSpheres;
22590
22714
  var shadowMatrices = this._shadowMatrices;
22591
22715
  var shadowCascades = scene.shadowCascades;
22716
+ var shadowFar = Math.min(scene.shadowDistance, camera.farClipPlane);
22717
+ ShadowUtils.getScaleAndBiasForLinearDistanceFade(Math.pow(shadowFar, 2), scene.shadowFadeBorder, this._shadowInfos);
22718
+ this._shadowInfos.x = light.shadowStrength;
22592
22719
  // set zero matrix to project the index out of max cascade
22593
22720
  if (shadowCascades > 1) {
22594
22721
  for(var i = shadowCascades * 4, n = splitBoundSpheres.length; i < n; i++){
@@ -22601,7 +22728,7 @@ var /**
22601
22728
  }
22602
22729
  var shaderData = scene.shaderData;
22603
22730
  shaderData.setFloatArray(CascadedShadowCasterPass._shadowMatricesProperty, this._shadowMatrices);
22604
- shaderData.setVector3(CascadedShadowCasterPass._shadowInfosProperty, this._shadowInfos);
22731
+ shaderData.setVector4(CascadedShadowCasterPass._shadowInfosProperty, this._shadowInfos);
22605
22732
  shaderData.setTexture(CascadedShadowCasterPass._shadowMapsProperty, this._depthTexture);
22606
22733
  shaderData.setFloatArray(CascadedShadowCasterPass._shadowSplitSpheresProperty, this._splitBoundSpheres);
22607
22734
  shaderData.setVector4(CascadedShadowCasterPass._shadowMapSize, this._shadowMapSize);
@@ -22637,10 +22764,13 @@ var /**
22637
22764
  return Math.sqrt(radius * radius / denominator);
22638
22765
  };
22639
22766
  _proto._updateShadowSettings = function _updateShadowSettings() {
22640
- var scene = this._camera.scene;
22767
+ var camera = this._camera;
22768
+ var scene = camera.scene;
22641
22769
  var shadowFormat = ShadowUtils.shadowDepthFormat(scene.shadowResolution, this._supportDepthTexture);
22642
22770
  var shadowResolution = ShadowUtils.shadowResolution(scene.shadowResolution);
22643
22771
  var shadowCascades = scene.shadowCascades;
22772
+ var shadowFar = Math.min(scene.shadowDistance, camera.farClipPlane);
22773
+ this._getCascadesSplitDistance(shadowFar);
22644
22774
  if (shadowFormat !== this._shadowMapFormat || shadowResolution !== this._shadowMapResolution || shadowCascades !== this._shadowCascadeMode) {
22645
22775
  this._shadowMapFormat = shadowFormat;
22646
22776
  this._shadowMapResolution = shadowResolution;
@@ -23088,14 +23218,14 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23088
23218
  /** @internal */ _this._cameraIndex = -1;
23089
23219
  _this._priority = 0;
23090
23220
  _this._shaderData = new ShaderData(ShaderDataGroup.Camera);
23091
- _this._isProjMatSetting = false;
23221
+ _this._isCustomViewMatrix = false;
23222
+ _this._isCustomProjectionMatrix = false;
23092
23223
  _this._nearClipPlane = 0.1;
23093
23224
  _this._farClipPlane = 100;
23094
23225
  _this._fieldOfView = 45;
23095
23226
  _this._orthographicSize = 10;
23096
23227
  _this._isProjectionDirty = true;
23097
23228
  _this._isInvProjMatDirty = true;
23098
- _this._isFrustumProjectDirty = true;
23099
23229
  _this._customAspectRatio = undefined;
23100
23230
  _this._renderTarget = null;
23101
23231
  _this._depthBufferParams = new miniprogram.Vector4();
@@ -23107,7 +23237,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23107
23237
  _this._transform = transform;
23108
23238
  _this._isViewMatrixDirty = transform.registerWorldChangeFlag();
23109
23239
  _this._isInvViewProjDirty = transform.registerWorldChangeFlag();
23110
- _this._frustumViewChangeFlag = transform.registerWorldChangeFlag();
23240
+ _this._frustumChangeFlag = transform.registerWorldChangeFlag();
23111
23241
  _this._renderPipeline = new BasicRenderPipeline(_assert_this_initialized(_this));
23112
23242
  _this._addResourceReferCount(_this.shaderData, 1);
23113
23243
  _this._updatePixelViewport();
@@ -23119,16 +23249,22 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23119
23249
  }
23120
23250
  var _proto = Camera1.prototype;
23121
23251
  /**
23252
+ * Restore the view matrix to the world matrix of the entity.
23253
+ */ _proto.resetViewMatrix = function resetViewMatrix() {
23254
+ this._isCustomViewMatrix = false;
23255
+ this._viewMatrixChange();
23256
+ };
23257
+ /**
23122
23258
  * Restore the automatic calculation of projection matrix through fieldOfView, nearClipPlane and farClipPlane.
23123
23259
  */ _proto.resetProjectionMatrix = function resetProjectionMatrix() {
23124
- this._isProjMatSetting = false;
23125
- this._projMatChange();
23260
+ this._isCustomProjectionMatrix = false;
23261
+ this._projectionMatrixChange();
23126
23262
  };
23127
23263
  /**
23128
23264
  * Restore the automatic calculation of the aspect ratio through the viewport aspect ratio.
23129
23265
  */ _proto.resetAspectRatio = function resetAspectRatio() {
23130
23266
  this._customAspectRatio = undefined;
23131
- this._projMatChange();
23267
+ this._projectionMatrixChange();
23132
23268
  };
23133
23269
  /**
23134
23270
  * Transform a point from world space to viewport space.
@@ -23258,10 +23394,9 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23258
23394
  context.replacementShader = this._replacementShader;
23259
23395
  context.replacementTag = this._replacementSubShaderTag;
23260
23396
  // compute cull frustum.
23261
- if (this.enableFrustumCulling && (this._frustumViewChangeFlag.flag || this._isFrustumProjectDirty)) {
23397
+ if (this.enableFrustumCulling && this._frustumChangeFlag.flag) {
23262
23398
  this._frustum.calculateFromMatrix(virtualCamera.viewProjectionMatrix);
23263
- this._frustumViewChangeFlag.flag = false;
23264
- this._isFrustumProjectDirty = false;
23399
+ this._frustumChangeFlag.flag = false;
23265
23400
  }
23266
23401
  this._updateShaderData();
23267
23402
  // union scene and camera macro.
@@ -23310,13 +23445,16 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23310
23445
  //@ts-ignore
23311
23446
  this._viewport._onValueChanged = null;
23312
23447
  this.engine.canvas._sizeUpdateFlagManager.removeListener(this._onPixelViewportChanged);
23448
+ //@ts-ignore
23449
+ this._viewport._onValueChanged = null;
23450
+ this.engine.canvas._sizeUpdateFlagManager.removeListener(this._onPixelViewportChanged);
23313
23451
  this._entity = null;
23314
23452
  this._globalShaderMacro = null;
23315
23453
  this._frustum = null;
23316
23454
  this._renderPipeline = null;
23317
23455
  this._virtualCamera = null;
23318
23456
  this._shaderData = null;
23319
- this._frustumViewChangeFlag = null;
23457
+ this._frustumChangeFlag = null;
23320
23458
  this._transform = null;
23321
23459
  this._isViewMatrixDirty = null;
23322
23460
  this._isInvViewProjDirty = null;
@@ -23338,11 +23476,16 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23338
23476
  var viewport = this._viewport;
23339
23477
  this._pixelViewport.set(viewport.x * width, viewport.y * height, viewport.z * width, viewport.w * height);
23340
23478
  };
23341
- _proto._projMatChange = function _projMatChange() {
23342
- this._isFrustumProjectDirty = true;
23479
+ _proto._viewMatrixChange = function _viewMatrixChange() {
23480
+ this._isViewMatrixDirty.flag = true;
23481
+ this._isInvViewProjDirty.flag = true;
23482
+ this._frustumChangeFlag.flag = true;
23483
+ };
23484
+ _proto._projectionMatrixChange = function _projectionMatrixChange() {
23343
23485
  this._isProjectionDirty = true;
23344
23486
  this._isInvProjMatDirty = true;
23345
23487
  this._isInvViewProjDirty.flag = true;
23488
+ this._frustumChangeFlag.flag = true;
23346
23489
  };
23347
23490
  _proto._innerViewportToWorldPoint = function _innerViewportToWorldPoint(x, y, z, invViewProjMat, out) {
23348
23491
  // Depth is a normalized value, 0 is nearPlane, 1 is farClipPlane.
@@ -23385,7 +23528,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23385
23528
  _proto._onPixelViewportChanged = function _onPixelViewportChanged() {
23386
23529
  this._updatePixelViewport();
23387
23530
  var _this__customAspectRatio;
23388
- (_this__customAspectRatio = this._customAspectRatio) != null ? _this__customAspectRatio : this._projMatChange();
23531
+ (_this__customAspectRatio = this._customAspectRatio) != null ? _this__customAspectRatio : this._projectionMatrixChange();
23389
23532
  };
23390
23533
  _create_class(Camera1, [
23391
23534
  {
@@ -23405,7 +23548,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23405
23548
  },
23406
23549
  set: function set(value) {
23407
23550
  this._nearClipPlane = value;
23408
- this._projMatChange();
23551
+ this._projectionMatrixChange();
23409
23552
  }
23410
23553
  },
23411
23554
  {
@@ -23417,7 +23560,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23417
23560
  },
23418
23561
  set: function set(value) {
23419
23562
  this._farClipPlane = value;
23420
- this._projMatChange();
23563
+ this._projectionMatrixChange();
23421
23564
  }
23422
23565
  },
23423
23566
  {
@@ -23429,7 +23572,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23429
23572
  },
23430
23573
  set: function set(value) {
23431
23574
  this._fieldOfView = value;
23432
- this._projMatChange();
23575
+ this._projectionMatrixChange();
23433
23576
  }
23434
23577
  },
23435
23578
  {
@@ -23444,7 +23587,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23444
23587
  },
23445
23588
  set: function set(value) {
23446
23589
  this._customAspectRatio = value;
23447
- this._projMatChange();
23590
+ this._projectionMatrixChange();
23448
23591
  }
23449
23592
  },
23450
23593
  {
@@ -23496,7 +23639,12 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23496
23639
  },
23497
23640
  set: function set(value) {
23498
23641
  this._virtualCamera.isOrthographic = value;
23499
- this._projMatChange();
23642
+ this._projectionMatrixChange();
23643
+ if (value) {
23644
+ this.shaderData.enableMacro("CAMERA_ORTHOGRAPHIC");
23645
+ } else {
23646
+ this.shaderData.disableMacro("CAMERA_ORTHOGRAPHIC");
23647
+ }
23500
23648
  }
23501
23649
  },
23502
23650
  {
@@ -23508,7 +23656,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23508
23656
  },
23509
23657
  set: function set(value) {
23510
23658
  this._orthographicSize = value;
23511
- this._projMatChange();
23659
+ this._projectionMatrixChange();
23512
23660
  }
23513
23661
  },
23514
23662
  {
@@ -23517,22 +23665,31 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23517
23665
  * View matrix.
23518
23666
  */ function get() {
23519
23667
  var viewMatrix = this._virtualCamera.viewMatrix;
23520
- if (this._isViewMatrixDirty.flag) {
23521
- this._isViewMatrixDirty.flag = false;
23522
- // Ignore scale.
23523
- var transform = this._transform;
23524
- miniprogram.Matrix.rotationTranslation(transform.worldRotationQuaternion, transform.worldPosition, viewMatrix);
23525
- viewMatrix.invert();
23526
- }
23668
+ if (!this._isViewMatrixDirty.flag || this._isCustomViewMatrix) {
23669
+ return viewMatrix;
23670
+ }
23671
+ this._isViewMatrixDirty.flag = false;
23672
+ // Ignore scale
23673
+ var transform = this._transform;
23674
+ miniprogram.Matrix.rotationTranslation(transform.worldRotationQuaternion, transform.worldPosition, viewMatrix);
23675
+ viewMatrix.invert();
23527
23676
  return viewMatrix;
23677
+ },
23678
+ set: function set(value) {
23679
+ this._virtualCamera.viewMatrix.copyFrom(value);
23680
+ this._isCustomViewMatrix = true;
23681
+ this._viewMatrixChange();
23528
23682
  }
23529
23683
  },
23530
23684
  {
23531
23685
  key: "projectionMatrix",
23532
- get: function get() {
23686
+ get: /**
23687
+ * The projection matrix is ​​calculated by the relevant parameters of the camera by default.
23688
+ * If it is manually set, the manual value will be maintained. Call resetProjectionMatrix() to restore it.
23689
+ */ function get() {
23533
23690
  var virtualCamera = this._virtualCamera;
23534
23691
  var projectionMatrix = virtualCamera.projectionMatrix;
23535
- if (!this._isProjectionDirty || this._isProjMatSetting) {
23692
+ if (!this._isProjectionDirty || this._isCustomProjectionMatrix) {
23536
23693
  return projectionMatrix;
23537
23694
  }
23538
23695
  this._isProjectionDirty = false;
@@ -23546,13 +23703,10 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23546
23703
  }
23547
23704
  return projectionMatrix;
23548
23705
  },
23549
- set: /**
23550
- * The projection matrix is ​​calculated by the relevant parameters of the camera by default.
23551
- * If it is manually set, the manual value will be maintained. Call resetProjectionMatrix() to restore it.
23552
- */ function set(value) {
23706
+ set: function set(value) {
23553
23707
  this._virtualCamera.projectionMatrix.copyFrom(value);
23554
- this._isProjMatSetting = true;
23555
- this._projMatChange();
23708
+ this._isCustomProjectionMatrix = true;
23709
+ this._projectionMatrixChange();
23556
23710
  }
23557
23711
  },
23558
23712
  {
@@ -23613,7 +23767,7 @@ __decorate([
23613
23767
  ], exports.Camera.prototype, "_cameraIndex", void 0);
23614
23768
  __decorate([
23615
23769
  ignoreClone
23616
- ], exports.Camera.prototype, "_frustumViewChangeFlag", void 0);
23770
+ ], exports.Camera.prototype, "_frustumChangeFlag", void 0);
23617
23771
  __decorate([
23618
23772
  ignoreClone
23619
23773
  ], exports.Camera.prototype, "_transform", void 0);
@@ -23800,6 +23954,7 @@ var MultiExecutor = /*#__PURE__*/ function() {
23800
23954
  * @param obj - class object
23801
23955
  */ Loader.registerClass = function registerClass(className, classDefine) {
23802
23956
  this._engineObjects[className] = classDefine;
23957
+ this._classNameMap.set(classDefine, className);
23803
23958
  };
23804
23959
  /**
23805
23960
  * Get the class object by class name.
@@ -23808,11 +23963,21 @@ var MultiExecutor = /*#__PURE__*/ function() {
23808
23963
  */ Loader.getClass = function getClass(className) {
23809
23964
  return this._engineObjects[className];
23810
23965
  };
23966
+ /**
23967
+ * Get the class name by class object.
23968
+ * @param obj - class object
23969
+ * @returns class name
23970
+ */ Loader.getClassName = function getClassName(obj) {
23971
+ return this._classNameMap.get(obj);
23972
+ };
23811
23973
  return Loader;
23812
23974
  }();
23813
23975
  (function() {
23814
23976
  Loader._engineObjects = {};
23815
23977
  })();
23978
+ (function() {
23979
+ Loader._classNameMap = new Map();
23980
+ })();
23816
23981
 
23817
23982
  /**
23818
23983
  * Alpha blend mode.
@@ -25246,6 +25411,7 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
25246
25411
  _this = EngineObject1.call(this, null) || this;
25247
25412
  _this.name = name;
25248
25413
  _this./** @internal */ _curveBindings = [];
25414
+ _this./** @internal */ _updateFlagManager = new UpdateFlagManager();
25249
25415
  _this._length = 0;
25250
25416
  _this._events = [];
25251
25417
  return _this;
@@ -25273,11 +25439,13 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
25273
25439
  while(--index >= 0 && eventTime < events[index].time);
25274
25440
  events.splice(index + 1, 0, newEvent);
25275
25441
  }
25442
+ this._updateFlagManager.dispatch();
25276
25443
  };
25277
25444
  /**
25278
25445
  * Clears all events from the clip.
25279
25446
  */ _proto.clearEvents = function clearEvents() {
25280
25447
  this._events.length = 0;
25448
+ this._updateFlagManager.dispatch();
25281
25449
  };
25282
25450
  _proto.addCurveBinding = function addCurveBinding(entityPath, componentType, propertyOrSetPropertyPathOrComponentIndex, curveOrSetPropertyPathOrGetPropertyPath, curveOrGetPropertyPath, curve) {
25283
25451
  var curveBinding = new AnimationClipCurveBinding();
@@ -26834,26 +27002,31 @@ exports.AnimatorLayerBlendingMode = void 0;
26834
27002
  }
26835
27003
  };
26836
27004
  _proto._saveAnimatorEventHandlers = function _saveAnimatorEventHandlers(state, animatorStateData) {
27005
+ var _this = this;
26837
27006
  var eventHandlerPool = this._animationEventHandlerPool;
26838
27007
  var scripts = [];
26839
- this._entity.getComponents(Script, scripts);
26840
- var scriptCount = scripts.length;
26841
27008
  var eventHandlers = animatorStateData.eventHandlers;
26842
- var events = state.clip.events;
26843
- eventHandlers.length = 0;
26844
- for(var i = 0, n = events.length; i < n; i++){
26845
- var event = events[i];
26846
- var eventHandler = eventHandlerPool.getFromPool();
26847
- var funcName = event.functionName;
26848
- var handlers = eventHandler.handlers;
26849
- eventHandler.event = event;
26850
- handlers.length = 0;
26851
- for(var j = scriptCount - 1; j >= 0; j--){
26852
- var handler = scripts[j][funcName];
26853
- handler && handlers.push(handler);
27009
+ var clipChangedListener = function() {
27010
+ _this._entity.getComponents(Script, scripts);
27011
+ var scriptCount = scripts.length;
27012
+ var events = state.clip.events;
27013
+ eventHandlers.length = 0;
27014
+ for(var i = 0, n = events.length; i < n; i++){
27015
+ var event = events[i];
27016
+ var eventHandler = eventHandlerPool.getFromPool();
27017
+ var funcName = event.functionName;
27018
+ var handlers = eventHandler.handlers;
27019
+ eventHandler.event = event;
27020
+ handlers.length = 0;
27021
+ for(var j = scriptCount - 1; j >= 0; j--){
27022
+ var handler = scripts[j][funcName];
27023
+ handler && handlers.push(handler);
27024
+ }
27025
+ eventHandlers.push(eventHandler);
26854
27026
  }
26855
- eventHandlers.push(eventHandler);
26856
- }
27027
+ };
27028
+ clipChangedListener();
27029
+ state._updateFlagManager.addListener(clipChangedListener);
26857
27030
  };
26858
27031
  _proto._clearCrossData = function _clearCrossData(animatorLayerData) {
26859
27032
  animatorLayerData.crossCurveMark++;
@@ -27464,9 +27637,11 @@ __decorate([
27464
27637
  this./** @internal */ _onStateEnterScripts = [];
27465
27638
  this./** @internal */ _onStateUpdateScripts = [];
27466
27639
  this./** @internal */ _onStateExitScripts = [];
27640
+ this./** @internal */ _updateFlagManager = new UpdateFlagManager();
27467
27641
  this._clipStartTime = 0;
27468
27642
  this._clipEndTime = 1;
27469
27643
  this._transitions = [];
27644
+ this._onClipChanged = this._onClipChanged.bind(this);
27470
27645
  }
27471
27646
  var _proto = AnimatorState.prototype;
27472
27647
  /**
@@ -27540,6 +27715,11 @@ __decorate([
27540
27715
  index2 !== -1 && this._onStateExitScripts.splice(index2, 1);
27541
27716
  }
27542
27717
  };
27718
+ /**
27719
+ * @internal
27720
+ */ _proto._onClipChanged = function _onClipChanged() {
27721
+ this._updateFlagManager.dispatch();
27722
+ };
27543
27723
  _create_class(AnimatorState, [
27544
27724
  {
27545
27725
  key: "transitions",
@@ -27557,8 +27737,17 @@ __decorate([
27557
27737
  return this._clip;
27558
27738
  },
27559
27739
  set: function set(clip) {
27740
+ var lastClip = this._clip;
27741
+ if (lastClip === clip) {
27742
+ return;
27743
+ }
27744
+ if (lastClip) {
27745
+ lastClip._updateFlagManager.removeListener(this._onClipChanged);
27746
+ }
27560
27747
  this._clip = clip;
27561
27748
  this._clipEndTime = Math.min(this._clipEndTime, 1);
27749
+ this._onClipChanged();
27750
+ clip && clip._updateFlagManager.addListener(this._onClipChanged);
27562
27751
  }
27563
27752
  },
27564
27753
  {
@@ -28265,6 +28454,7 @@ __decorate([
28265
28454
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["RotationOverLifetime"] = 0x40eb95e4] = "RotationOverLifetime";
28266
28455
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["TextureSheetAnimation"] = 0xbc524e5] = "TextureSheetAnimation";
28267
28456
  ParticleRandomSubSeeds[ParticleRandomSubSeeds["Shape"] = 0xaf502044] = "Shape";
28457
+ ParticleRandomSubSeeds[ParticleRandomSubSeeds["GravityModifier"] = 0xa47b8c4d] = "GravityModifier";
28268
28458
  })(ParticleRandomSubSeeds || (ParticleRandomSubSeeds = {}));
28269
28459
 
28270
28460
  /**
@@ -28978,6 +29168,7 @@ var MainModule = /*#__PURE__*/ function() {
28978
29168
  /** @internal */ this._startColorRand = new miniprogram.Rand(0, ParticleRandomSubSeeds.StartColor);
28979
29169
  /** @internal */ this._startSizeRand = new miniprogram.Rand(0, ParticleRandomSubSeeds.StartSize);
28980
29170
  /** @internal */ this._startRotationRand = new miniprogram.Rand(0, ParticleRandomSubSeeds.StartRotation);
29171
+ this._gravityModifierRand = new miniprogram.Rand(0, ParticleRandomSubSeeds.GravityModifier);
28981
29172
  this._gravity = new miniprogram.Vector3();
28982
29173
  this._generator = generator;
28983
29174
  }
@@ -29038,7 +29229,7 @@ var MainModule = /*#__PURE__*/ function() {
29038
29229
  break;
29039
29230
  }
29040
29231
  var particleGravity = this._gravity;
29041
- var gravityModifierValue = this.gravityModifier.evaluate(undefined, undefined);
29232
+ var gravityModifierValue = this.gravityModifier.evaluate(undefined, this._gravityModifierRand.random());
29042
29233
  miniprogram.Vector3.scale(renderer.scene.physics.gravity, gravityModifierValue, particleGravity);
29043
29234
  shaderData.setVector3(MainModule._gravity, particleGravity);
29044
29235
  shaderData.setInt(MainModule._simulationSpace, this.simulationSpace);
@@ -29157,6 +29348,9 @@ __decorate([
29157
29348
  __decorate([
29158
29349
  ignoreClone
29159
29350
  ], MainModule.prototype, "_startRotationRand", void 0);
29351
+ __decorate([
29352
+ ignoreClone
29353
+ ], MainModule.prototype, "_gravityModifierRand", void 0);
29160
29354
  __decorate([
29161
29355
  ignoreClone
29162
29356
  ], MainModule.prototype, "_generator", void 0);
@@ -29827,7 +30021,8 @@ __decorate([
29827
30021
  var transform = this._renderer.entity.transform;
29828
30022
  var shape = this.emission.shape;
29829
30023
  for(var i = 0; i < count; i++){
29830
- if (shape) {
30024
+ var _shape;
30025
+ if ((_shape = shape) == null ? void 0 : _shape.enabled) {
29831
30026
  shape._generatePositionAndDirection(this.emission._shapeRand, time, position, direction);
29832
30027
  var positionScale = this.main._getPositionScale();
29833
30028
  position.multiply(positionScale);
@@ -30407,7 +30602,7 @@ __decorate([
30407
30602
  * Base class for all particle shapes.
30408
30603
  */ var BaseShape = /*#__PURE__*/ function() {
30409
30604
  function BaseShape() {
30410
- /** Specifies whether the ShapeModule is enabled or disabled. */ this.enable = true;
30605
+ /** Specifies whether the ShapeModule is enabled or disabled. */ this.enabled = true;
30411
30606
  /** Randomizes the starting direction of particles. */ this.randomDirectionAmount = 0;
30412
30607
  }
30413
30608
  var _proto = BaseShape.prototype;
@@ -30471,14 +30666,14 @@ __decorate([
30471
30666
 
30472
30667
  /**
30473
30668
  * The emission shape.
30474
- */ var ParticleShapeType;
30669
+ */ exports.ParticleShapeType = void 0;
30475
30670
  (function(ParticleShapeType) {
30476
30671
  ParticleShapeType[ParticleShapeType[/** Emit from the volume of a box. */ "Box"] = 0] = "Box";
30477
30672
  ParticleShapeType[ParticleShapeType[/** Emit from a circle. */ "Circle"] = 1] = "Circle";
30478
30673
  ParticleShapeType[ParticleShapeType[/** Emit from the base of a cone. */ "Cone"] = 2] = "Cone";
30479
30674
  ParticleShapeType[ParticleShapeType[/** Emit from a half-sphere. */ "Hemisphere"] = 3] = "Hemisphere";
30480
30675
  ParticleShapeType[ParticleShapeType[/** Emit from a sphere. */ "Sphere"] = 4] = "Sphere";
30481
- })(ParticleShapeType || (ParticleShapeType = {}));
30676
+ })(exports.ParticleShapeType || (exports.ParticleShapeType = {}));
30482
30677
 
30483
30678
  /**
30484
30679
  * Particle shape that emits particles from a box.
@@ -30486,9 +30681,9 @@ __decorate([
30486
30681
  _inherits(BoxShape, BaseShape1);
30487
30682
  function BoxShape() {
30488
30683
  var _this;
30489
- _this = BaseShape1.call(this) || this;
30684
+ _this = BaseShape1.apply(this, arguments) || this;
30685
+ _this.shapeType = exports.ParticleShapeType.Box;
30490
30686
  /** The size of the box. */ _this.size = new miniprogram.Vector3(1, 1, 1);
30491
- _this.shapeType = ParticleShapeType.Box;
30492
30687
  return _this;
30493
30688
  }
30494
30689
  var _proto = BoxShape.prototype;
@@ -30525,12 +30720,12 @@ __decorate([
30525
30720
  _inherits(CircleShape, BaseShape1);
30526
30721
  function CircleShape() {
30527
30722
  var _this;
30528
- _this = BaseShape1.call(this) || this;
30723
+ _this = BaseShape1.apply(this, arguments) || this;
30724
+ _this.shapeType = exports.ParticleShapeType.Circle;
30529
30725
  /** Radius of the shape to emit particles from. */ _this.radius = 1.0;
30530
30726
  /** Angle of the circle arc to emit particles from. */ _this.arc = 360.0;
30531
30727
  /** The mode to generate particles around the arc. */ _this.arcMode = exports.ParticleShapeArcMode.Random;
30532
30728
  /** The speed of complete 360 degree rotation. */ _this.arcSpeed = 1.0;
30533
- _this.shapeType = ParticleShapeType.Circle;
30534
30729
  return _this;
30535
30730
  }
30536
30731
  var _proto = CircleShape.prototype;
@@ -30566,12 +30761,12 @@ __decorate([
30566
30761
  _inherits(ConeShape, BaseShape1);
30567
30762
  function ConeShape() {
30568
30763
  var _this;
30569
- _this = BaseShape1.call(this) || this;
30764
+ _this = BaseShape1.apply(this, arguments) || this;
30765
+ _this.shapeType = exports.ParticleShapeType.Cone;
30570
30766
  /** Angle of the cone to emit particles from. */ _this.angle = 25.0;
30571
30767
  /** Radius of the shape to emit particles from. */ _this.radius = 1.0;
30572
30768
  /** Length of the cone to emit particles from. */ _this.length = 5.0;
30573
30769
  /** Cone emitter type. */ _this.emitType = /** Emit particles from the base of the cone. */ 0;
30574
- _this.shapeType = ParticleShapeType.Cone;
30575
30770
  return _this;
30576
30771
  }
30577
30772
  var _proto = ConeShape.prototype;
@@ -30631,9 +30826,9 @@ exports.ConeEmitType = void 0;
30631
30826
  _inherits(HemisphereShape, BaseShape1);
30632
30827
  function HemisphereShape() {
30633
30828
  var _this;
30634
- _this = BaseShape1.call(this) || this;
30829
+ _this = BaseShape1.apply(this, arguments) || this;
30830
+ _this.shapeType = exports.ParticleShapeType.Hemisphere;
30635
30831
  /** Radius of the shape to emit particles from. */ _this.radius = 1.0;
30636
- _this.shapeType = ParticleShapeType.Hemisphere;
30637
30832
  return _this;
30638
30833
  }
30639
30834
  var _proto = HemisphereShape.prototype;
@@ -30656,9 +30851,9 @@ exports.ConeEmitType = void 0;
30656
30851
  _inherits(SphereShape, BaseShape1);
30657
30852
  function SphereShape() {
30658
30853
  var _this;
30659
- _this = BaseShape1.call(this) || this;
30854
+ _this = BaseShape1.apply(this, arguments) || this;
30855
+ _this.shapeType = exports.ParticleShapeType.Sphere;
30660
30856
  /** Radius of the shape to emit particles from. */ _this.radius = 1.0;
30661
- _this.shapeType = ParticleShapeType.Sphere;
30662
30857
  return _this;
30663
30858
  }
30664
30859
  var _proto = SphereShape.prototype;