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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/main.js +664 -566
  2. package/dist/main.js.map +1 -1
  3. package/dist/miniprogram.js +664 -566
  4. package/dist/module.js +760 -662
  5. package/dist/module.js.map +1 -1
  6. package/package.json +3 -3
  7. package/types/2d/atlas/types.d.ts +2 -0
  8. package/types/2d/text/TextRenderer.d.ts +1 -0
  9. package/types/Camera.d.ts +11 -5
  10. package/types/Engine.d.ts +4 -2
  11. package/types/SystemInfo.d.ts +2 -0
  12. package/types/Utils.d.ts +6 -0
  13. package/types/asset/AssetType.d.ts +2 -0
  14. package/types/asset/ResourceManager.d.ts +2 -0
  15. package/types/input/InputManager.d.ts +0 -2
  16. package/types/input/interface/IInput.d.ts +0 -8
  17. package/types/mesh/PrimitiveMesh.d.ts +22 -0
  18. package/types/shaderlib/ShaderFactory.d.ts +5 -1
  19. package/types/xr/XRPose.d.ts +15 -0
  20. package/types/xr/feature/XRFeature.d.ts +16 -0
  21. package/types/xr/feature/XRFeatureManager.d.ts +65 -0
  22. package/types/xr/feature/XRFeatureType.d.ts +13 -0
  23. package/types/xr/feature/camera/XRCameraManager.d.ts +26 -0
  24. package/types/xr/feature/hitTest/TrackableType.d.ts +10 -0
  25. package/types/xr/feature/hitTest/XRHitResult.d.ts +19 -0
  26. package/types/xr/feature/hitTest/XRHitTest.d.ts +39 -0
  27. package/types/xr/feature/hitTest/XRHitTestManager.d.ts +38 -0
  28. package/types/xr/feature/hitTest/XRHitTestType.d.ts +16 -0
  29. package/types/xr/feature/movementTracking/XRMovementTracking.d.ts +18 -0
  30. package/types/xr/feature/movementTracking/XRMovementTrackingManager.d.ts +10 -0
  31. package/types/xr/feature/movementTracking/XRMovementTrackingMode.d.ts +5 -0
  32. package/types/xr/feature/trackable/XRRequestTrackingState.d.ts +11 -0
  33. package/types/xr/feature/trackable/XRTrackableFeature.d.ts +38 -0
  34. package/types/xr/feature/trackable/XRTrackableManager.d.ts +41 -0
  35. package/types/xr/feature/trackable/XRTracked.d.ts +1 -0
  36. package/types/xr/feature/trackable/anchor/XRAnchor.d.ts +6 -0
  37. package/types/xr/feature/trackable/anchor/XRAnchorTracking.d.ts +37 -0
  38. package/types/xr/feature/trackable/anchor/XRAnchorTrackingManager.d.ts +20 -0
  39. package/types/xr/feature/trackable/anchor/XRRequestAnchor.d.ts +15 -0
  40. package/types/xr/feature/trackable/image/XRImageTracking.d.ts +24 -0
  41. package/types/xr/feature/trackable/image/XRImageTrackingManager.d.ts +31 -0
  42. package/types/xr/feature/trackable/image/XRReferenceImage.d.ts +11 -0
  43. package/types/xr/feature/trackable/image/XRRequestImage.d.ts +13 -0
  44. package/types/xr/feature/trackable/image/XRTrackedImage.d.ts +8 -0
  45. package/types/xr/feature/trackable/plane/XRPlaneMode.d.ts +13 -0
  46. package/types/xr/feature/trackable/plane/XRPlaneTracking.d.ts +23 -0
  47. package/types/xr/feature/trackable/plane/XRPlaneTrackingManager.d.ts +11 -0
  48. package/types/xr/feature/trackable/plane/XRRequestPlane.d.ts +12 -0
  49. package/types/xr/feature/trackable/plane/XRTrackedPlane.d.ts +20 -0
  50. package/types/xr/index.d.ts +25 -0
  51. package/types/xr/input/XRCamera.d.ts +15 -0
  52. package/types/xr/input/XRController.d.ts +38 -0
  53. package/types/xr/input/XRControllerPoseMode.d.ts +9 -0
  54. package/types/xr/input/XRInput.d.ts +8 -0
  55. package/types/xr/input/XRInputButton.d.ts +19 -0
  56. package/types/xr/input/XRInputEvent.d.ts +24 -0
  57. package/types/xr/input/XRInputEventType.d.ts +11 -0
  58. package/types/xr/input/XRInputManager.d.ts +31 -0
  59. package/types/xr/input/XRInputType.d.ts +23 -0
  60. package/types/xr/input/XRTargetRayMode.d.ts +12 -0
  61. package/types/xr/input/XRTrackedInputDevice.d.ts +21 -0
  62. package/types/xr/input/XRTrackedUpdateFlag.d.ts +11 -0
  63. package/types/xr/input/XRTrackingState.d.ts +11 -0
  64. package/types/xr/session/XRSessionManager.d.ts +45 -0
  65. package/types/xr/session/XRSessionMode.d.ts +8 -0
  66. package/types/xr/session/XRSessionState.d.ts +13 -0
  67. package/types/RenderPipeline/MeshRenderElement.d.ts +0 -19
  68. package/types/RenderPipeline/SpriteElement.d.ts +0 -15
  69. package/types/RenderPipeline/SpriteMaskElement.d.ts +0 -12
  70. package/types/RenderPipeline/TextRenderElement.d.ts +0 -8
  71. package/types/asset/IRefObject.d.ts +0 -2
  72. package/types/asset/RefObject.d.ts +0 -27
  73. package/types/base/Event.d.ts +0 -24
  74. package/types/base/Util.d.ts +0 -14
  75. /package/types/{2d/data/RenderData2D.d.ts → xr/feature/trackable/XRRequestTracking.d.ts} +0 -0
@@ -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
 
@@ -3731,7 +3408,11 @@ var ShaderFactory = /*#__PURE__*/ function() {
3731
3408
  }
3732
3409
  ShaderLib[includeName] = includeSource;
3733
3410
  };
3734
- ShaderFactory.parseIncludes = function parseIncludes(src) {
3411
+ /**
3412
+ * @param regex The default regex is for engine's builtin glsl `#include` syntax,
3413
+ * since `ShaderLab` use the same parsing function but different syntax for `#include` --- `/^[ \t]*#include +"([\w\d.]+)"/gm`
3414
+ */ ShaderFactory.parseIncludes = function parseIncludes(src, regex) {
3415
+ if (regex === void 0) regex = /^[ \t]*#include +<([\w\d.]+)>/gm;
3735
3416
  var replace = function replace(match, slice) {
3736
3417
  var replace = ShaderLib[slice];
3737
3418
  if (replace === undefined) {
@@ -3740,7 +3421,6 @@ var ShaderFactory = /*#__PURE__*/ function() {
3740
3421
  }
3741
3422
  return ShaderFactory.parseIncludes(replace);
3742
3423
  };
3743
- var regex = /^[ \t]*#include +<([\w\d.]+)>/gm;
3744
3424
  return src.replace(regex, replace);
3745
3425
  };
3746
3426
  /**
@@ -6722,7 +6402,7 @@ SlicedSpriteAssembler = __decorate([
6722
6402
  _this._byteLength = byteLength;
6723
6403
  _this._platformBuffer = engine._hardwareRenderer.createPlatformBuffer(type, byteLength, bufferUsage, data);
6724
6404
  if (readable) {
6725
- var buffer = (data.constructor === ArrayBuffer ? data : data.buffer).slice(0, byteLength);
6405
+ var buffer = data.constructor === ArrayBuffer ? data.slice(0) : data.buffer.slice(data.byteOffset, data.byteOffset + byteLength);
6726
6406
  _this._data = new Uint8Array(buffer);
6727
6407
  }
6728
6408
  }
@@ -9931,6 +9611,10 @@ var VertexElementIndex;
9931
9611
  var sphereInfo = primitiveInfo;
9932
9612
  PrimitiveMesh._setSphereData(this.resource, sphereInfo.radius, sphereInfo.segments, sphereInfo.noLongerAccessible, true, sphereInfo.vertexBuffer);
9933
9613
  break;
9614
+ case 7:
9615
+ var CCSphereInfo = primitiveInfo;
9616
+ PrimitiveMesh._setSubdivisionSurfaceSphereData(this.resource, CCSphereInfo.radius, CCSphereInfo.step, CCSphereInfo.noLongerAccessible, true, CCSphereInfo.vertexBuffer);
9617
+ break;
9934
9618
  case 1:
9935
9619
  var cuboidInfo = primitiveInfo;
9936
9620
  PrimitiveMesh._setCuboidData(this.resource, cuboidInfo.width, cuboidInfo.height, cuboidInfo.depth, cuboidInfo.noLongerAccessible, true, cuboidInfo.vertexBuffer);
@@ -9968,6 +9652,7 @@ var PrimitiveType;
9968
9652
  PrimitiveType[PrimitiveType["Torus"] = 4] = "Torus";
9969
9653
  PrimitiveType[PrimitiveType["Cone"] = 5] = "Cone";
9970
9654
  PrimitiveType[PrimitiveType["Capsule"] = 6] = "Capsule";
9655
+ PrimitiveType[PrimitiveType["CCSphere"] = 7] = "CCSphere";
9971
9656
  })(PrimitiveType || (PrimitiveType = {}));
9972
9657
  /**
9973
9658
  * @internal
@@ -9989,6 +9674,19 @@ var PrimitiveType;
9989
9674
  }
9990
9675
  return SphereRestoreInfo;
9991
9676
  }(PrimitiveRestoreInfo);
9677
+ /**
9678
+ * @internal
9679
+ */ var SubdivisionSurfaceSphereRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
9680
+ _inherits(SubdivisionSurfaceSphereRestoreInfo, PrimitiveRestoreInfo);
9681
+ function SubdivisionSurfaceSphereRestoreInfo(radius, step, vertexBuffer, noLongerAccessible) {
9682
+ var _this;
9683
+ _this = PrimitiveRestoreInfo.call(this, 7, vertexBuffer, noLongerAccessible) || this;
9684
+ _this.radius = radius;
9685
+ _this.step = step;
9686
+ return _this;
9687
+ }
9688
+ return SubdivisionSurfaceSphereRestoreInfo;
9689
+ }(PrimitiveRestoreInfo);
9992
9690
  /**
9993
9691
  * @internal
9994
9692
  */ var CuboidRestoreInfo = /*#__PURE__*/ function(PrimitiveRestoreInfo) {
@@ -10103,6 +9801,24 @@ var PrimitiveType;
10103
9801
  return sphereMesh;
10104
9802
  };
10105
9803
  /**
9804
+ * Create a sphere mesh by implementing Catmull-Clark Surface Subdivision Algorithm.
9805
+ * Max step is limited to 6.
9806
+ * @param engine - Engine
9807
+ * @param radius - Sphere radius
9808
+ * @param step - Number of subdiv steps
9809
+ * @param noLongerAccessible - No longer access the vertices of the mesh after creation
9810
+ * @returns Sphere model mesh
9811
+ */ PrimitiveMesh.createSubdivisionSurfaceSphere = function createSubdivisionSurfaceSphere(engine, radius, step, noLongerAccessible) {
9812
+ if (radius === void 0) radius = 0.5;
9813
+ if (step === void 0) step = 3;
9814
+ if (noLongerAccessible === void 0) noLongerAccessible = true;
9815
+ var sphereMesh = new ModelMesh(engine);
9816
+ PrimitiveMesh._setSubdivisionSurfaceSphereData(sphereMesh, radius, step, noLongerAccessible, false);
9817
+ var vertexBuffer = sphereMesh.vertexBufferBindings[0].buffer;
9818
+ engine.resourceManager.addContentRestorer(new PrimitiveMeshRestorer(sphereMesh, new SubdivisionSurfaceSphereRestoreInfo(radius, step, vertexBuffer, noLongerAccessible)));
9819
+ return sphereMesh;
9820
+ };
9821
+ /**
10106
9822
  * Create a cuboid mesh.
10107
9823
  * @param engine - Engine
10108
9824
  * @param width - Cuboid width
@@ -10232,6 +9948,90 @@ var PrimitiveType;
10232
9948
  };
10233
9949
  /**
10234
9950
  * @internal
9951
+ */ PrimitiveMesh._setSubdivisionSurfaceSphereData = function _setSubdivisionSurfaceSphereData(sphereMesh, radius, step, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
9952
+ // Max step is limited to 6. Because 7 step will generate a single mesh with over 98306 vertices
9953
+ step = miniprogram.MathUtil.clamp(Math.floor(step), 1, 6);
9954
+ var positions = new Float32Array(3 * (6 * Math.pow(4, step) + 2));
9955
+ var cells = new Float32Array(24 * Math.pow(4, step));
9956
+ PrimitiveMesh._subdiveCatmullClark(step, positions, cells);
9957
+ var positionCount = positions.length / 3;
9958
+ var cellsCount = cells.length / 4;
9959
+ var poleOffset = positionCount + Math.pow(2, step + 1) - 1;
9960
+ // 16 extra vertices for pole uv
9961
+ // 2 vertices at each pole are idle
9962
+ var vertexCount = poleOffset + 16;
9963
+ var vertices = new Float32Array(vertexCount * 8);
9964
+ var indices = PrimitiveMesh._generateIndices(sphereMesh.engine, positionCount, cellsCount * 6);
9965
+ var seamCount = 0;
9966
+ var seamVertices = {};
9967
+ // Get normals, uvs, and scale to radius
9968
+ for(var i = 0; i < positionCount; i++){
9969
+ var offset = 3 * i;
9970
+ var x = positions[offset];
9971
+ var y = positions[offset + 1];
9972
+ var z = positions[offset + 2];
9973
+ var reciprocalLength = 1 / Math.sqrt(x * x + y * y + z * z);
9974
+ x *= reciprocalLength;
9975
+ y *= reciprocalLength;
9976
+ z *= reciprocalLength;
9977
+ offset = 8 * i;
9978
+ vertices[offset] = x * radius;
9979
+ vertices[offset + 1] = y * radius;
9980
+ vertices[offset + 2] = z * radius;
9981
+ vertices[offset + 3] = x;
9982
+ vertices[offset + 4] = y;
9983
+ vertices[offset + 5] = z;
9984
+ vertices[offset + 6] = (Math.PI - Math.atan2(z, x)) / (2 * Math.PI);
9985
+ vertices[offset + 7] = Math.acos(y) / Math.PI;
9986
+ if (vertices[offset + 6] === 0) {
9987
+ // Generate seam vertex
9988
+ var seamOffset = 8 * (positionCount + seamCount++);
9989
+ vertices.set(vertices.subarray(offset, offset + 8), seamOffset);
9990
+ vertices[seamOffset + 6] = 1.0;
9991
+ // Cache seam vertex
9992
+ seamVertices[offset / 8] = seamOffset / 8;
9993
+ }
9994
+ }
9995
+ // Get indices
9996
+ var offset1 = 0;
9997
+ this._spherePoleIdx = 0;
9998
+ for(var i1 = 0; i1 < cellsCount; i1++){
9999
+ var idx = 4 * i1;
10000
+ var indexA = cells[idx];
10001
+ var indexB = cells[idx + 1];
10002
+ var indexC = cells[idx + 2];
10003
+ var indexD = cells[idx + 3];
10004
+ // Handle seam by replacing vertex index to seam vertex index if necessary
10005
+ var floatIndexA = 8 * indexA;
10006
+ var floatIndexB = 8 * indexB;
10007
+ var floatIndexC = 8 * indexC;
10008
+ var floatIndexD = 8 * indexD;
10009
+ // If center Z is negative
10010
+ if (vertices[floatIndexA + 2] + vertices[floatIndexB + 2] + vertices[floatIndexC + 2] < 0) {
10011
+ vertices[floatIndexA + 6] === 0 && (indexA = seamVertices[indexA]);
10012
+ vertices[floatIndexB + 6] === 0 && (indexB = seamVertices[indexB]);
10013
+ vertices[floatIndexC + 6] === 0 && (indexC = seamVertices[indexC]);
10014
+ vertices[floatIndexD + 6] === 0 && (indexD = seamVertices[indexD]);
10015
+ }
10016
+ indices[offset1] = indexA;
10017
+ indices[offset1 + 1] = indexB;
10018
+ indices[offset1 + 2] = indexC;
10019
+ this._generateAndReplacePoleUV(indices, vertices, offset1, poleOffset);
10020
+ indices[offset1 + 3] = indexA;
10021
+ indices[offset1 + 4] = indexC;
10022
+ indices[offset1 + 5] = indexD;
10023
+ this._generateAndReplacePoleUV(indices, vertices, offset1 + 3, poleOffset);
10024
+ offset1 += 6;
10025
+ }
10026
+ if (!isRestoreMode) {
10027
+ var bounds = sphereMesh.bounds;
10028
+ bounds.min.set(-radius, -radius, -radius);
10029
+ bounds.max.set(radius, radius, radius);
10030
+ }
10031
+ PrimitiveMesh._initialize(sphereMesh, vertices, indices, noLongerAccessible, isRestoreMode, restoreVertexBuffer);
10032
+ };
10033
+ /**
10034
+ * @internal
10235
10035
  */ PrimitiveMesh._setSphereData = function _setSphereData(sphereMesh, radius, segments, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
10236
10036
  segments = Math.max(2, Math.floor(segments));
10237
10037
  var count = segments + 1;
@@ -10292,6 +10092,135 @@ var PrimitiveType;
10292
10092
  };
10293
10093
  /**
10294
10094
  * @internal
10095
+ */ PrimitiveMesh._subdiveCatmullClark = function _subdiveCatmullClark(step, positions, cells) {
10096
+ var edges = new Map();
10097
+ var faces = new Array();
10098
+ positions.set(PrimitiveMesh._sphereSeedPositions);
10099
+ cells.set(PrimitiveMesh._sphereSeedCells);
10100
+ for(var i = 0; i < step; i++){
10101
+ var cellCount = 6 * Math.pow(4, i);
10102
+ var positionCount = 4 * cellCount + 2;
10103
+ edges.clear();
10104
+ faces.length = 0;
10105
+ // Get cell face's facePoint
10106
+ for(var j = 0; j < cellCount; j++){
10107
+ var face = faces[j] = {
10108
+ facePoint: new miniprogram.Vector3(),
10109
+ adjacentEdges: new Array(4)
10110
+ };
10111
+ // Get cell's edgePoint
10112
+ for(var k = 0; k < 4; k++){
10113
+ var offset = 3 * cells[4 * j + k];
10114
+ face.facePoint.x += 0.25 * positions[offset];
10115
+ face.facePoint.y += 0.25 * positions[offset + 1];
10116
+ face.facePoint.z += 0.25 * positions[offset + 2];
10117
+ }
10118
+ // Get cell edges
10119
+ for(var k1 = 0; k1 < 4; k1++){
10120
+ var vertexIdxA = cells[4 * j + k1];
10121
+ var vertexIdxB = cells[4 * j + (k1 + 1) % 4];
10122
+ var edgeIdxKey = Math.min(vertexIdxA, vertexIdxB) * positionCount + Math.max(vertexIdxA, vertexIdxB);
10123
+ if (!edges.has(edgeIdxKey)) {
10124
+ var edge = {
10125
+ edgePoint: new miniprogram.Vector3(),
10126
+ edgePointIndex: undefined
10127
+ };
10128
+ var offsetA = 3 * vertexIdxA;
10129
+ var offsetB = 3 * vertexIdxB;
10130
+ 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]));
10131
+ edges.set(edgeIdxKey, edge);
10132
+ }
10133
+ var edge1 = edges.get(edgeIdxKey);
10134
+ face.adjacentEdges[k1] = edge1;
10135
+ var edgePoint = edge1.edgePoint;
10136
+ var facePoint = face.facePoint;
10137
+ edgePoint.x += 0.25 * facePoint.x;
10138
+ edgePoint.y += 0.25 * facePoint.y;
10139
+ edgePoint.z += 0.25 * facePoint.z;
10140
+ }
10141
+ }
10142
+ var prePointCount = cellCount + 2;
10143
+ var edgePointOffset = prePointCount + cellCount;
10144
+ var pointIdx = 0;
10145
+ this._sphereEdgeIdx = 0;
10146
+ var preCells = cells.slice(0, 4 * cellCount);
10147
+ // Get New positions, which consists of updated positions of existing points, face points and edge points
10148
+ for(var j1 = 0; j1 < cellCount; j1++){
10149
+ // Add face point to new positions
10150
+ var face1 = faces[j1];
10151
+ face1.facePoint.copyToArray(positions, 3 * (prePointCount + j1));
10152
+ // Get the face point index
10153
+ var ic = prePointCount + j1;
10154
+ var id = void 0, ib = void 0, temp = void 0;
10155
+ // ia -- id -- ia
10156
+ // | | |
10157
+ // ib -- ic -- ib
10158
+ // | | |
10159
+ // ia -- id -- ia
10160
+ for(var k2 = 0; k2 < 4; k2++){
10161
+ // Get the updated existing point index
10162
+ var ia = preCells[pointIdx++];
10163
+ // ib and id share four edge points in one cell
10164
+ switch(k2){
10165
+ case 0:
10166
+ {
10167
+ var edgeB = face1.adjacentEdges[k2 % 4];
10168
+ var edgeD = face1.adjacentEdges[(k2 + 3) % 4];
10169
+ ib = this._calculateEdgeIndex(positions, edgeB, edgePointOffset);
10170
+ id = this._calculateEdgeIndex(positions, edgeD, edgePointOffset);
10171
+ temp = id;
10172
+ break;
10173
+ }
10174
+ case 1:
10175
+ case 2:
10176
+ {
10177
+ var edgeB1 = face1.adjacentEdges[k2 % 4];
10178
+ id = ib;
10179
+ ib = this._calculateEdgeIndex(positions, edgeB1, edgePointOffset);
10180
+ break;
10181
+ }
10182
+ case 3:
10183
+ {
10184
+ id = ib;
10185
+ ib = temp;
10186
+ break;
10187
+ }
10188
+ }
10189
+ var idx = 4 * (4 * j1 + k2);
10190
+ cells[idx] = ia;
10191
+ cells[idx + 1] = ib;
10192
+ cells[idx + 2] = ic;
10193
+ cells[idx + 3] = id;
10194
+ }
10195
+ }
10196
+ }
10197
+ };
10198
+ /**
10199
+ * Duplicate vertices at the poles and adjust their UV coordinates.
10200
+ */ PrimitiveMesh._generateAndReplacePoleUV = function _generateAndReplacePoleUV(indices, vertices, idx, poleOffset) {
10201
+ var v = vertices[8 * indices[idx] + 7];
10202
+ if (v === 0 || v === 1) {
10203
+ var offset = 8 * indices[idx];
10204
+ var addedOffset = 8 * (poleOffset + this._spherePoleIdx);
10205
+ vertices.set(vertices.subarray(offset, offset + 8), addedOffset);
10206
+ vertices[addedOffset + 6] = 0.5 * (vertices[offset + 6] + vertices[8 * indices[idx + 1] + 6] + vertices[8 * indices[idx + 2] + 6] - 0.5);
10207
+ indices[idx] = poleOffset + this._spherePoleIdx++;
10208
+ }
10209
+ };
10210
+ /**
10211
+ * Get edge point index for subdivision surface sphere.
10212
+ */ PrimitiveMesh._calculateEdgeIndex = function _calculateEdgeIndex(positions, edge, offset) {
10213
+ if (edge.edgePointIndex !== undefined) {
10214
+ return edge.edgePointIndex;
10215
+ } else {
10216
+ edge.edgePoint.copyToArray(positions, 3 * (offset + PrimitiveMesh._sphereEdgeIdx));
10217
+ var index = offset + PrimitiveMesh._sphereEdgeIdx++;
10218
+ edge.edgePointIndex = index;
10219
+ return index;
10220
+ }
10221
+ };
10222
+ /**
10223
+ * @internal
10295
10224
  */ PrimitiveMesh._setCuboidData = function _setCuboidData(cuboidMesh, width, height, depth, noLongerAccessible, isRestoreMode, restoreVertexBuffer) {
10296
10225
  var halfWidth = width / 2;
10297
10226
  var halfHeight = height / 2;
@@ -10921,6 +10850,68 @@ var PrimitiveType;
10921
10850
  (function() {
10922
10851
  PrimitiveMesh._tempVec30 = new miniprogram.Vector3();
10923
10852
  })();
10853
+ (function() {
10854
+ PrimitiveMesh._sphereSeedPositions = new Float32Array([
10855
+ -1,
10856
+ 1,
10857
+ 1,
10858
+ -1,
10859
+ -1,
10860
+ 1,
10861
+ 1,
10862
+ -1,
10863
+ 1,
10864
+ 1,
10865
+ 1,
10866
+ 1,
10867
+ 1,
10868
+ -1,
10869
+ -1,
10870
+ 1,
10871
+ 1,
10872
+ -1,
10873
+ -1,
10874
+ -1,
10875
+ -1,
10876
+ -1,
10877
+ 1,
10878
+ -1
10879
+ ]);
10880
+ })();
10881
+ (function() {
10882
+ PrimitiveMesh._sphereSeedCells = new Float32Array([
10883
+ 0,
10884
+ 1,
10885
+ 2,
10886
+ 3,
10887
+ 3,
10888
+ 2,
10889
+ 4,
10890
+ 5,
10891
+ 5,
10892
+ 4,
10893
+ 6,
10894
+ 7,
10895
+ 7,
10896
+ 0,
10897
+ 3,
10898
+ 5,
10899
+ 7,
10900
+ 6,
10901
+ 1,
10902
+ 0,
10903
+ 6,
10904
+ 4,
10905
+ 2,
10906
+ 1
10907
+ ]);
10908
+ })();
10909
+ (function() {
10910
+ PrimitiveMesh._sphereEdgeIdx = 0;
10911
+ })();
10912
+ (function() {
10913
+ PrimitiveMesh._spherePoleIdx = 0;
10914
+ })();
10924
10915
 
10925
10916
  /**
10926
10917
  * Mesh skin data, equal glTF skins define
@@ -11465,8 +11456,10 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
11465
11456
  }
11466
11457
  mesh.addSubMesh(this._getSubMeshFromPool(vertexStartIndex, vertexCount));
11467
11458
  batchedQueue[curMeshIndex] = preElement;
11468
- this._vertexBuffers[_flushId].setData(vertices, 0, 0, vertexIndex);
11469
- this._indiceBuffers[_flushId].setData(indices, 0, 0, indiceIndex);
11459
+ // Set data option use Discard, or will resulted in performance slowdown when open antialias and cross-rendering of 3D and 2D elements.
11460
+ // Device: iphone X(16.7.2)、iphone 15 pro max(17.1.1)、iphone XR(17.1.2) etc.
11461
+ this._vertexBuffers[_flushId].setData(vertices, 0, 0, vertexIndex, exports.SetDataOptions.Discard);
11462
+ this._indiceBuffers[_flushId].setData(indices, 0, 0, indiceIndex, exports.SetDataOptions.Discard);
11470
11463
  };
11471
11464
  _proto._getSubMeshFromPool = function _getSubMeshFromPool(start, count) {
11472
11465
  var subMesh = this._subMeshPool.getFromPool();
@@ -12496,6 +12489,9 @@ var /**
12496
12489
  __decorate([
12497
12490
  assignmentClone
12498
12491
  ], SpriteMask.prototype, "influenceLayers", void 0);
12492
+ __decorate([
12493
+ ignoreClone
12494
+ ], SpriteMask.prototype, "_verticesData", void 0);
12499
12495
  __decorate([
12500
12496
  ignoreClone
12501
12497
  ], SpriteMask.prototype, "_sprite", void 0);
@@ -12779,8 +12775,8 @@ var /**
12779
12775
  } else {
12780
12776
  word += char;
12781
12777
  wordWidth += charInfo.xAdvance;
12782
- wordMaxAscent = lineMaxAscent = Math.max(wordMaxAscent, ascent);
12783
- wordMaxDescent = lineMaxDescent = Math.max(wordMaxDescent, descent);
12778
+ wordMaxAscent = Math.max(wordMaxAscent, ascent);
12779
+ wordMaxDescent = Math.max(wordMaxDescent, descent);
12784
12780
  }
12785
12781
  }
12786
12782
  }
@@ -12901,6 +12897,9 @@ var /**
12901
12897
  var baseline = Math.ceil(context.measureText(TextUtils._measureBaseline).width);
12902
12898
  var height = baseline * TextUtils._heightMultiplier;
12903
12899
  baseline = TextUtils._baselineMultiplier * baseline | 0;
12900
+ var _extendHeight = TextUtils._extendHeight;
12901
+ height += _extendHeight;
12902
+ baseline += _extendHeight * 0.5;
12904
12903
  canvas.width = width;
12905
12904
  canvas.height = height;
12906
12905
  context.font = fontString;
@@ -12935,6 +12934,7 @@ var /**
12935
12934
  }
12936
12935
  if (top !== -1 && bottom !== -1) {
12937
12936
  ascent = baseline - top;
12937
+ // Baseline belong to descent
12938
12938
  descent = bottom - baseline + 1;
12939
12939
  size = ascent + descent;
12940
12940
  }
@@ -13010,6 +13010,10 @@ var /**
13010
13010
  "fangsong"
13011
13011
  ];
13012
13012
  })();
13013
+ (function() {
13014
+ // _extendHeight used to extend the height of canvas, because in miniprogram performance is different from h5.
13015
+ /** @internal */ TextUtils._extendHeight = 0;
13016
+ })();
13013
13017
  (function() {
13014
13018
  /** These characters are all tall to help calculate the height required for text. */ TextUtils._measureString = "|\xc9q\xc5";
13015
13019
  })();
@@ -13100,7 +13104,8 @@ var /**
13100
13104
  _proto._createFontAtlas = function _createFontAtlas() {
13101
13105
  var _this = this, engine = _this._engine;
13102
13106
  var fontAtlas = new FontAtlas(engine);
13103
- var texture = new Texture2D(engine, 256, 256);
13107
+ var texture = new Texture2D(engine, 256, 256, exports.TextureFormat.R8G8B8A8, false);
13108
+ texture.filterMode = exports.TextureFilterMode.Bilinear;
13104
13109
  fontAtlas.texture = texture;
13105
13110
  fontAtlas.isGCIgnored = texture.isGCIgnored = true;
13106
13111
  this._fontAtlases.push(fontAtlas);
@@ -13338,7 +13343,7 @@ var /**
13338
13343
  /**
13339
13344
  * @internal
13340
13345
  */ _proto._render = function _render(context) {
13341
- if (this._text === "" || this.enableWrapping && this.width <= 0 || this.overflowMode === exports.OverflowMode.Truncate && this.height <= 0) {
13346
+ if (this._isTextNoVisible()) {
13342
13347
  return;
13343
13348
  }
13344
13349
  if (this._isContainDirtyFlag(0x10)) {
@@ -13430,8 +13435,8 @@ var /**
13430
13435
  }
13431
13436
  };
13432
13437
  _proto._updateLocalData = function _updateLocalData() {
13433
- var _this = this, color = _this.color, charRenderDatas = _this._charRenderDatas, charFont = _this._subFont;
13434
13438
  var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
13439
+ var _this = this, color = _this.color, charRenderDatas = _this._charRenderDatas, charFont = _this._subFont;
13435
13440
  var textMetrics = this.enableWrapping ? TextUtils.measureTextWithWrap(this) : TextUtils.measureTextWithoutWrap(this);
13436
13441
  var height = textMetrics.height, lines = textMetrics.lines, lineWidths = textMetrics.lineWidths, lineHeight = textMetrics.lineHeight, lineMaxSizes = textMetrics.lineMaxSizes;
13437
13442
  var charRenderDataPool = TextRenderer._charRenderDataPool;
@@ -13499,7 +13504,7 @@ var /**
13499
13504
  var left = startX * pixelsPerUnitReciprocal;
13500
13505
  var right = (startX + w) * pixelsPerUnitReciprocal;
13501
13506
  var top = (startY + ascent) * pixelsPerUnitReciprocal;
13502
- var bottom = (startY - descent + 1) * pixelsPerUnitReciprocal;
13507
+ var bottom = (startY - descent) * pixelsPerUnitReciprocal;
13503
13508
  localPositions.set(left, top, right, bottom);
13504
13509
  i === firstLine && (maxY = Math.max(maxY, top));
13505
13510
  minY = Math.min(minY, bottom);
@@ -13540,6 +13545,9 @@ var /**
13540
13545
  Renderer1.prototype._onTransformChanged.call(this, bit);
13541
13546
  this._setDirtyFlagTrue(0x4 | 0x8);
13542
13547
  };
13548
+ _proto._isTextNoVisible = function _isTextNoVisible() {
13549
+ return this._text === "" || this._fontSize === 0 || this.enableWrapping && this.width <= 0 || this.overflowMode === exports.OverflowMode.Truncate && this.height <= 0;
13550
+ };
13543
13551
  _create_class(TextRenderer, [
13544
13552
  {
13545
13553
  key: "color",
@@ -13742,6 +13750,16 @@ var /**
13742
13750
  get: /**
13743
13751
  * The bounding volume of the TextRenderer.
13744
13752
  */ function get() {
13753
+ if (this._isTextNoVisible()) {
13754
+ if (this._isContainDirtyFlag(0x8)) {
13755
+ var localBounds = this._localBounds;
13756
+ localBounds.min.set(0, 0, 0);
13757
+ localBounds.max.set(0, 0, 0);
13758
+ this._updateBounds(this._bounds);
13759
+ this._setDirtyFlagFalse(0x8);
13760
+ }
13761
+ return this._bounds;
13762
+ }
13745
13763
  this._isContainDirtyFlag(0x1) && this._resetSubFont();
13746
13764
  this._isContainDirtyFlag(0x2) && this._updateLocalData();
13747
13765
  this._isContainDirtyFlag(0x4) && this._updatePosition();
@@ -14763,6 +14781,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData1) {
14763
14781
  AssetType[/** Cube Compress Texture. */ "KTXCube"] = "KTXCube";
14764
14782
  AssetType[/** KTX2 Compress Texture */ "KTX2"] = "KTX2";
14765
14783
  AssetType[/** Sprite. */ "Sprite"] = "Sprite";
14784
+ AssetType[/** PrimitiveMesh. */ "PrimitiveMesh"] = "PrimitiveMesh";
14766
14785
  AssetType[/** Sprite Atlas. */ "SpriteAtlas"] = "SpriteAtlas";
14767
14786
  AssetType[/** Ambient light. */ "Env"] = "Environment";
14768
14787
  AssetType[/** Scene. */ "Scene"] = "Scene";
@@ -15148,6 +15167,7 @@ var /** @internal */ PromiseState;
15148
15167
  this./** The number of retries after failing to load assets. */ retryCount = 1;
15149
15168
  this./** Retry delay time after failed to load assets, in milliseconds. */ retryInterval = 0;
15150
15169
  this./** The default timeout period for loading assets, in milliseconds. */ timeout = Infinity;
15170
+ this./** Base url for loading assets. */ baseUrl = null;
15151
15171
  this._loadingPromises = {};
15152
15172
  this._assetPool = Object.create(null);
15153
15173
  this._assetUrlPool = Object.create(null);
@@ -15351,6 +15371,8 @@ var /** @internal */ PromiseState;
15351
15371
  // Check url mapping
15352
15372
  var itemURL = item.url;
15353
15373
  var url = this._virtualPathMap[itemURL] ? this._virtualPathMap[itemURL] : itemURL;
15374
+ // Not absolute and base url is set
15375
+ if (!Utils.isAbsoluteUrl(url) && this.baseUrl) url = Utils.resolveAbsoluteUrl(this.baseUrl, url);
15354
15376
  // Parse url
15355
15377
  var _this__parseURL = this._parseURL(url), assetBaseURL = _this__parseURL.assetBaseURL, queryPath = _this__parseURL.queryPath;
15356
15378
  var paths = queryPath ? this._parseQueryPath(queryPath) : [];
@@ -15730,6 +15752,66 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
15730
15752
  }
15731
15753
  }
15732
15754
  };
15755
+ /**
15756
+ * @internal
15757
+ */ SystemInfo._detectSIMDSupported = function _detectSIMDSupported() {
15758
+ if (this._simdSupported === null) {
15759
+ this._simdSupported = WebAssembly.validate(new Uint8Array([
15760
+ 0,
15761
+ 97,
15762
+ 115,
15763
+ 109,
15764
+ 1,
15765
+ 0,
15766
+ 0,
15767
+ 0,
15768
+ 1,
15769
+ 4,
15770
+ 1,
15771
+ 96,
15772
+ 0,
15773
+ 0,
15774
+ 3,
15775
+ 3,
15776
+ 2,
15777
+ 0,
15778
+ 0,
15779
+ 5,
15780
+ 3,
15781
+ 1,
15782
+ 0,
15783
+ 1,
15784
+ 12,
15785
+ 1,
15786
+ 0,
15787
+ 10,
15788
+ 22,
15789
+ 2,
15790
+ 12,
15791
+ 0,
15792
+ 65,
15793
+ 0,
15794
+ 65,
15795
+ 0,
15796
+ 65,
15797
+ 0,
15798
+ 252,
15799
+ 10,
15800
+ 0,
15801
+ 0,
15802
+ 11,
15803
+ 7,
15804
+ 0,
15805
+ 65,
15806
+ 0,
15807
+ 253,
15808
+ 15,
15809
+ 26,
15810
+ 11
15811
+ ]));
15812
+ }
15813
+ return this._simdSupported;
15814
+ };
15733
15815
  _create_class(SystemInfo, null, [
15734
15816
  {
15735
15817
  key: "devicePixelRatio",
@@ -15748,6 +15830,9 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
15748
15830
  (function() {
15749
15831
  /** The operating system is running on. */ SystemInfo.operatingSystem = "";
15750
15832
  })();
15833
+ (function() {
15834
+ /** Whether the system support SIMD. */ SystemInfo._simdSupported = null;
15835
+ })();
15751
15836
  SystemInfo._initialize();
15752
15837
 
15753
15838
  /**
@@ -15978,7 +16063,7 @@ SystemInfo._initialize();
15978
16063
  * Keyboard Manager.
15979
16064
  * @internal
15980
16065
  */ var KeyboardManager = /*#__PURE__*/ function() {
15981
- function KeyboardManager(engine) {
16066
+ function KeyboardManager(engine, target) {
15982
16067
  /** @internal */ this._curHeldDownKeyToIndexMap = [];
15983
16068
  /** @internal */ this._upKeyToFrameCountMap = [];
15984
16069
  /** @internal */ this._downKeyToFrameCountMap = [];
@@ -15986,17 +16071,11 @@ SystemInfo._initialize();
15986
16071
  /** @internal */ this._curFrameDownList = new DisorderedArray();
15987
16072
  /** @internal */ this._curFrameUpList = new DisorderedArray();
15988
16073
  this._nativeEvents = [];
15989
- this._hadListener = false;
15990
- // @ts-ignore
15991
- var htmlCanvas = engine._canvas._webCanvas;
15992
16074
  this._engine = engine;
15993
- this._htmlCanvas = htmlCanvas;
15994
- // Need to set tabIndex to make the canvas focus.
15995
- htmlCanvas.tabIndex = htmlCanvas.tabIndex;
16075
+ this._onBlur = this._onBlur.bind(this);
15996
16076
  this._onKeyEvent = this._onKeyEvent.bind(this);
15997
- htmlCanvas.addEventListener("keydown", this._onKeyEvent);
15998
- htmlCanvas.addEventListener("keyup", this._onKeyEvent);
15999
- this._hadListener = true;
16077
+ this._target = target;
16078
+ this._addEventListener();
16000
16079
  }
16001
16080
  var _proto = KeyboardManager.prototype;
16002
16081
  /**
@@ -16048,35 +16127,8 @@ SystemInfo._initialize();
16048
16127
  };
16049
16128
  /**
16050
16129
  * @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
16130
  */ _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
- }
16131
+ this._removeEventListener();
16080
16132
  this._curHeldDownKeyToIndexMap.length = 0;
16081
16133
  this._curHeldDownKeyToIndexMap = null;
16082
16134
  this._upKeyToFrameCountMap.length = 0;
@@ -16091,12 +16143,30 @@ SystemInfo._initialize();
16091
16143
  this._curFrameDownList = null;
16092
16144
  this._curFrameUpList.length = 0;
16093
16145
  this._curFrameUpList = null;
16094
- this._htmlCanvas = null;
16095
16146
  this._engine = null;
16096
16147
  };
16148
+ _proto._onBlur = function _onBlur() {
16149
+ this._curHeldDownKeyToIndexMap.length = 0;
16150
+ this._curFrameHeldDownList.length = 0;
16151
+ this._curFrameDownList.length = 0;
16152
+ this._curFrameUpList.length = 0;
16153
+ this._nativeEvents.length = 0;
16154
+ };
16097
16155
  _proto._onKeyEvent = function _onKeyEvent(evt) {
16098
16156
  this._nativeEvents.push(evt);
16099
16157
  };
16158
+ _proto._addEventListener = function _addEventListener() {
16159
+ var _this = this, target = _this._target;
16160
+ target.addEventListener("keydown", this._onKeyEvent);
16161
+ target.addEventListener("keyup", this._onKeyEvent);
16162
+ target.addEventListener("blur", this._onBlur);
16163
+ };
16164
+ _proto._removeEventListener = function _removeEventListener() {
16165
+ var _this = this, target = _this._target;
16166
+ target.removeEventListener("keydown", this._onKeyEvent);
16167
+ target.removeEventListener("keyup", this._onKeyEvent);
16168
+ target.removeEventListener("blur", this._onBlur);
16169
+ };
16100
16170
  return KeyboardManager;
16101
16171
  }();
16102
16172
 
@@ -18060,7 +18130,7 @@ __decorate([
18060
18130
  * Pointer Manager.
18061
18131
  * @internal
18062
18132
  */ var PointerManager = /*#__PURE__*/ function() {
18063
- function PointerManager(engine) {
18133
+ function PointerManager(engine, target) {
18064
18134
  /** @internal */ this._pointers = [];
18065
18135
  /** @internal */ this._multiPointerEnabled = true;
18066
18136
  /** @internal */ this._buttons = exports.PointerButton.None;
@@ -18069,16 +18139,18 @@ __decorate([
18069
18139
  /** @internal */ this._upList = new DisorderedArray();
18070
18140
  /** @internal */ this._downList = new DisorderedArray();
18071
18141
  this._nativeEvents = [];
18072
- this._hadListener = false;
18073
- // @ts-ignore
18074
- var htmlCanvas = engine._canvas._webCanvas;
18142
+ if (_instanceof(target, Window)) {
18143
+ throw "Do not set window as target because window cannot listen to pointer leave event.";
18144
+ }
18075
18145
  this._engine = engine;
18146
+ this._target = target;
18076
18147
  this._canvas = engine.canvas;
18077
- this._htmlCanvas = htmlCanvas;
18078
- this._onPointerEvent = this._onPointerEvent.bind(this);
18079
- this._onFocus();
18148
+ // @ts-ignore
18149
+ this._htmlCanvas = engine._canvas._webCanvas;
18080
18150
  // If there are no compatibility issues, navigator.maxTouchPoints should be used here
18081
18151
  this._pointerPool = new Array(11);
18152
+ this._onPointerEvent = this._onPointerEvent.bind(this);
18153
+ this._addEventListener();
18082
18154
  }
18083
18155
  var _proto = PointerManager.prototype;
18084
18156
  /**
@@ -18148,7 +18220,8 @@ __decorate([
18148
18220
  var length = events.length;
18149
18221
  if (length > 0) {
18150
18222
  for(var i1 = 0; i1 < length; i1++){
18151
- switch(events[i1].type){
18223
+ var event = events[i1];
18224
+ switch(event.type){
18152
18225
  case "pointerdown":
18153
18226
  pointer.phase = exports.PointerPhase.Down;
18154
18227
  pointer._firePointerDown(rayCastEntity);
@@ -18170,66 +18243,14 @@ __decorate([
18170
18243
  };
18171
18244
  /**
18172
18245
  * @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
18246
  */ _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
- }
18247
+ this._removeEventListener();
18213
18248
  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
18249
  this._nativeEvents.length = 0;
18222
- this._nativeEvents = null;
18223
- this._upMap.length = 0;
18224
- this._upMap = null;
18225
18250
  this._downMap.length = 0;
18226
- this._downMap = null;
18227
- this._htmlCanvas = null;
18228
- this._canvas = null;
18229
- this._engine = null;
18251
+ this._upMap.length = 0;
18230
18252
  };
18231
18253
  _proto._onPointerEvent = function _onPointerEvent(evt) {
18232
- evt.type === "pointerdown" && this._htmlCanvas.focus();
18233
18254
  this._nativeEvents.push(evt);
18234
18255
  };
18235
18256
  _proto._getPointerByID = function _getPointerByID(pointerId) {
@@ -18312,6 +18333,26 @@ __decorate([
18312
18333
  }
18313
18334
  return null;
18314
18335
  };
18336
+ _proto._addEventListener = function _addEventListener() {
18337
+ var _this = this, target = _this._target, onPointerEvent = _this._onPointerEvent;
18338
+ target.addEventListener("pointerdown", onPointerEvent);
18339
+ target.addEventListener("pointerup", onPointerEvent);
18340
+ target.addEventListener("pointerleave", onPointerEvent);
18341
+ target.addEventListener("pointermove", onPointerEvent);
18342
+ target.addEventListener("pointercancel", onPointerEvent);
18343
+ };
18344
+ _proto._removeEventListener = function _removeEventListener() {
18345
+ var _this = this, target = _this._target, onPointerEvent = _this._onPointerEvent;
18346
+ target.removeEventListener("pointerdown", onPointerEvent);
18347
+ target.removeEventListener("pointerup", onPointerEvent);
18348
+ target.removeEventListener("pointerleave", onPointerEvent);
18349
+ target.removeEventListener("pointermove", onPointerEvent);
18350
+ target.removeEventListener("pointercancel", onPointerEvent);
18351
+ this._nativeEvents.length = 0;
18352
+ this._pointers.length = 0;
18353
+ this._downList.length = 0;
18354
+ this._upList.length = 0;
18355
+ };
18315
18356
  return PointerManager;
18316
18357
  }();
18317
18358
  (function() {
@@ -18328,15 +18369,12 @@ __decorate([
18328
18369
  * Wheel Manager.
18329
18370
  * @internal
18330
18371
  */ var WheelManager = /*#__PURE__*/ function() {
18331
- function WheelManager(engine) {
18372
+ function WheelManager(engine, target) {
18332
18373
  /** @internal */ this._delta = new miniprogram.Vector3();
18333
18374
  this._nativeEvents = [];
18334
- // @ts-ignore
18335
- var htmlCanvas = engine._canvas._webCanvas;
18336
18375
  this._onWheelEvent = this._onWheelEvent.bind(this);
18337
- htmlCanvas.addEventListener("wheel", this._onWheelEvent);
18338
- this._canvas = htmlCanvas;
18339
- this._hadListener = true;
18376
+ this._target = target;
18377
+ this._addEventListener();
18340
18378
  }
18341
18379
  var _proto = WheelManager.prototype;
18342
18380
  /**
@@ -18357,35 +18395,24 @@ __decorate([
18357
18395
  };
18358
18396
  /**
18359
18397
  * @internal
18360
- */ _proto._onFocus = function _onFocus() {
18361
- if (!this._hadListener) {
18362
- this._canvas.addEventListener("wheel", this._onWheelEvent);
18363
- this._hadListener = true;
18364
- }
18398
+ */ _proto._addEventListener = function _addEventListener() {
18399
+ this._target.addEventListener("wheel", this._onWheelEvent);
18365
18400
  };
18366
18401
  /**
18367
18402
  * @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
- }
18403
+ */ _proto._removeEventListener = function _removeEventListener() {
18404
+ this._target.removeEventListener("wheel", this._onWheelEvent);
18405
+ this._nativeEvents.length = 0;
18406
+ this._delta.set(0, 0, 0);
18375
18407
  };
18376
18408
  /**
18377
18409
  * @internal
18378
18410
  */ _proto._destroy = function _destroy() {
18379
- if (this._hadListener) {
18380
- this._canvas.removeEventListener("wheel", this._onWheelEvent);
18381
- this._hadListener = false;
18382
- }
18411
+ this._removeEventListener();
18383
18412
  this._nativeEvents = null;
18384
- this._canvas = null;
18385
18413
  this._delta = null;
18386
18414
  };
18387
18415
  _proto._onWheelEvent = function _onWheelEvent(evt) {
18388
- evt.cancelable && evt.preventDefault();
18389
18416
  this._nativeEvents.push(evt);
18390
18417
  };
18391
18418
  return WheelManager;
@@ -18394,19 +18421,19 @@ __decorate([
18394
18421
  /**
18395
18422
  * InputManager manages device input such as mouse, touch, keyboard, etc.
18396
18423
  */ var InputManager = /*#__PURE__*/ function() {
18397
- function InputManager(engine) {
18424
+ function InputManager(engine, inputOptions) {
18398
18425
  /** Sometimes the input module will not be initialized, such as off-screen rendering. */ this._initialized = false;
18399
18426
  this._engine = engine;
18400
18427
  // @ts-ignore
18401
18428
  var canvas = engine._canvas._webCanvas;
18402
18429
  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);
18430
+ var _inputOptions, _inputOptions1, _inputOptions2;
18431
+ var _inputOptions_wheelTarget;
18432
+ this._wheelManager = new WheelManager(engine, (_inputOptions_wheelTarget = (_inputOptions = inputOptions) == null ? void 0 : _inputOptions.wheelTarget) != null ? _inputOptions_wheelTarget : canvas);
18433
+ var _inputOptions_pointerTarget;
18434
+ this._pointerManager = new PointerManager(engine, (_inputOptions_pointerTarget = (_inputOptions1 = inputOptions) == null ? void 0 : _inputOptions1.pointerTarget) != null ? _inputOptions_pointerTarget : canvas);
18435
+ var _inputOptions_keyboardTarget;
18436
+ this._keyboardManager = new KeyboardManager(engine, (_inputOptions_keyboardTarget = (_inputOptions2 = inputOptions) == null ? void 0 : _inputOptions2.keyboardTarget) != null ? _inputOptions_keyboardTarget : engineMiniprogramAdapter.window);
18410
18437
  this._initialized = true;
18411
18438
  }
18412
18439
  }
@@ -18519,8 +18546,6 @@ __decorate([
18519
18546
  * @internal
18520
18547
  */ _proto._destroy = function _destroy() {
18521
18548
  if (this._initialized) {
18522
- engineMiniprogramAdapter.window.removeEventListener("blur", this._onBlur);
18523
- engineMiniprogramAdapter.window.removeEventListener("focus", this._onFocus);
18524
18549
  this._wheelManager._destroy();
18525
18550
  this._wheelManager = null;
18526
18551
  this._pointerManager._destroy();
@@ -18529,16 +18554,6 @@ __decorate([
18529
18554
  this._keyboardManager = null;
18530
18555
  }
18531
18556
  };
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
18557
  _create_class(InputManager, [
18543
18558
  {
18544
18559
  key: "pointers",
@@ -18581,6 +18596,8 @@ __decorate([
18581
18596
  _this = ReferResource1.call(this, engine) || this;
18582
18597
  /** @internal */ _this._renderStates = [] // todo: later will as a part of shaderData when shader effect frame is OK, that is more powerful and flexible.
18583
18598
  ;
18599
+ /** @internal */ _this._priority = 0 // todo: temporary resolution of submesh rendering order issue.
18600
+ ;
18584
18601
  _this._shaderData = new ShaderData(ShaderDataGroup.Material);
18585
18602
  _this.shader = shader;
18586
18603
  return _this;
@@ -19034,7 +19051,7 @@ ShaderPool.init();
19034
19051
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
19035
19052
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
19036
19053
  _this._textDefaultFont.isGCIgnored = true;
19037
- _this.inputManager = new InputManager(_assert_this_initialized(_this));
19054
+ _this.inputManager = new InputManager(_assert_this_initialized(_this), configuration.input);
19038
19055
  var xrDevice = configuration.xrDevice;
19039
19056
  if (xrDevice) {
19040
19057
  _this.xrManager = new XRManager();
@@ -19050,11 +19067,11 @@ ShaderPool.init();
19050
19067
  }
19051
19068
  var meshMagentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
19052
19069
  meshMagentaMaterial.isGCIgnored = true;
19053
- meshMagentaMaterial.shaderData.setColor("material_BaseColor", new Color(1.0, 0.0, 1.01, 1.0));
19070
+ meshMagentaMaterial.shaderData.setColor("material_BaseColor", new miniprogram.Color(1.0, 0.0, 1.01, 1.0));
19054
19071
  _this._meshMagentaMaterial = meshMagentaMaterial;
19055
19072
  var particleMagentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("particle-shader"));
19056
19073
  particleMagentaMaterial.isGCIgnored = true;
19057
- particleMagentaMaterial.shaderData.setColor("material_BaseColor", new Color(1.0, 0.0, 1.01, 1.0));
19074
+ particleMagentaMaterial.shaderData.setColor("material_BaseColor", new miniprogram.Color(1.0, 0.0, 1.01, 1.0));
19058
19075
  _this._particleMagentaMaterial = particleMagentaMaterial;
19059
19076
  var innerSettings = _this._settings;
19060
19077
  var colorSpace = configuration.colorSpace || exports.ColorSpace.Linear;
@@ -21870,12 +21887,48 @@ var passNum = 0;
21870
21887
  /**
21871
21888
  * @internal
21872
21889
  */ RenderQueue._compareFromNearToFar = function _compareFromNearToFar(a, b) {
21873
- return a.data.component.priority - b.data.component.priority || a.data.component._distanceForSort - b.data.component._distanceForSort;
21890
+ var dataA = a.data;
21891
+ var dataB = b.data;
21892
+ var componentA = dataA.component;
21893
+ var componentB = dataB.component;
21894
+ var priorityOrder = componentA.priority - componentB.priority;
21895
+ if (priorityOrder !== 0) {
21896
+ return priorityOrder;
21897
+ }
21898
+ // make suer from the same renderer.
21899
+ if (componentA.instanceId === componentB.instanceId) {
21900
+ return dataA.material._priority - dataB.material._priority || componentA._distanceForSort - componentB._distanceForSort;
21901
+ } else {
21902
+ var distanceDiff = componentA._distanceForSort - componentB._distanceForSort;
21903
+ if (distanceDiff === 0) {
21904
+ return componentA.instanceId - componentB.instanceId;
21905
+ } else {
21906
+ return distanceDiff;
21907
+ }
21908
+ }
21874
21909
  };
21875
21910
  /**
21876
21911
  * @internal
21877
21912
  */ RenderQueue._compareFromFarToNear = function _compareFromFarToNear(a, b) {
21878
- return a.data.component.priority - b.data.component.priority || b.data.component._distanceForSort - a.data.component._distanceForSort;
21913
+ var dataA = a.data;
21914
+ var dataB = b.data;
21915
+ var componentA = dataA.component;
21916
+ var componentB = dataB.component;
21917
+ var priorityOrder = componentA.priority - componentB.priority;
21918
+ if (priorityOrder !== 0) {
21919
+ return priorityOrder;
21920
+ }
21921
+ // make suer from the same renderer.
21922
+ if (componentA.instanceId === componentB.instanceId) {
21923
+ return dataA.material._priority - dataB.material._priority || componentB._distanceForSort - componentA._distanceForSort;
21924
+ } else {
21925
+ var distanceDiff = componentB._distanceForSort - componentA._distanceForSort;
21926
+ if (distanceDiff === 0) {
21927
+ return componentA.instanceId - componentB.instanceId;
21928
+ } else {
21929
+ return distanceDiff;
21930
+ }
21931
+ }
21879
21932
  };
21880
21933
  return RenderQueue;
21881
21934
  }();
@@ -23088,14 +23141,14 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23088
23141
  /** @internal */ _this._cameraIndex = -1;
23089
23142
  _this._priority = 0;
23090
23143
  _this._shaderData = new ShaderData(ShaderDataGroup.Camera);
23091
- _this._isProjMatSetting = false;
23144
+ _this._isCustomViewMatrix = false;
23145
+ _this._isCustomProjectionMatrix = false;
23092
23146
  _this._nearClipPlane = 0.1;
23093
23147
  _this._farClipPlane = 100;
23094
23148
  _this._fieldOfView = 45;
23095
23149
  _this._orthographicSize = 10;
23096
23150
  _this._isProjectionDirty = true;
23097
23151
  _this._isInvProjMatDirty = true;
23098
- _this._isFrustumProjectDirty = true;
23099
23152
  _this._customAspectRatio = undefined;
23100
23153
  _this._renderTarget = null;
23101
23154
  _this._depthBufferParams = new miniprogram.Vector4();
@@ -23107,7 +23160,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23107
23160
  _this._transform = transform;
23108
23161
  _this._isViewMatrixDirty = transform.registerWorldChangeFlag();
23109
23162
  _this._isInvViewProjDirty = transform.registerWorldChangeFlag();
23110
- _this._frustumViewChangeFlag = transform.registerWorldChangeFlag();
23163
+ _this._frustumChangeFlag = transform.registerWorldChangeFlag();
23111
23164
  _this._renderPipeline = new BasicRenderPipeline(_assert_this_initialized(_this));
23112
23165
  _this._addResourceReferCount(_this.shaderData, 1);
23113
23166
  _this._updatePixelViewport();
@@ -23119,16 +23172,22 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23119
23172
  }
23120
23173
  var _proto = Camera1.prototype;
23121
23174
  /**
23175
+ * Restore the view matrix to the world matrix of the entity.
23176
+ */ _proto.resetViewMatrix = function resetViewMatrix() {
23177
+ this._isCustomViewMatrix = false;
23178
+ this._viewMatrixChange();
23179
+ };
23180
+ /**
23122
23181
  * Restore the automatic calculation of projection matrix through fieldOfView, nearClipPlane and farClipPlane.
23123
23182
  */ _proto.resetProjectionMatrix = function resetProjectionMatrix() {
23124
- this._isProjMatSetting = false;
23125
- this._projMatChange();
23183
+ this._isCustomProjectionMatrix = false;
23184
+ this._projectionMatrixChange();
23126
23185
  };
23127
23186
  /**
23128
23187
  * Restore the automatic calculation of the aspect ratio through the viewport aspect ratio.
23129
23188
  */ _proto.resetAspectRatio = function resetAspectRatio() {
23130
23189
  this._customAspectRatio = undefined;
23131
- this._projMatChange();
23190
+ this._projectionMatrixChange();
23132
23191
  };
23133
23192
  /**
23134
23193
  * Transform a point from world space to viewport space.
@@ -23258,10 +23317,9 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23258
23317
  context.replacementShader = this._replacementShader;
23259
23318
  context.replacementTag = this._replacementSubShaderTag;
23260
23319
  // compute cull frustum.
23261
- if (this.enableFrustumCulling && (this._frustumViewChangeFlag.flag || this._isFrustumProjectDirty)) {
23320
+ if (this.enableFrustumCulling && this._frustumChangeFlag.flag) {
23262
23321
  this._frustum.calculateFromMatrix(virtualCamera.viewProjectionMatrix);
23263
- this._frustumViewChangeFlag.flag = false;
23264
- this._isFrustumProjectDirty = false;
23322
+ this._frustumChangeFlag.flag = false;
23265
23323
  }
23266
23324
  this._updateShaderData();
23267
23325
  // union scene and camera macro.
@@ -23316,7 +23374,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23316
23374
  this._renderPipeline = null;
23317
23375
  this._virtualCamera = null;
23318
23376
  this._shaderData = null;
23319
- this._frustumViewChangeFlag = null;
23377
+ this._frustumChangeFlag = null;
23320
23378
  this._transform = null;
23321
23379
  this._isViewMatrixDirty = null;
23322
23380
  this._isInvViewProjDirty = null;
@@ -23338,11 +23396,16 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23338
23396
  var viewport = this._viewport;
23339
23397
  this._pixelViewport.set(viewport.x * width, viewport.y * height, viewport.z * width, viewport.w * height);
23340
23398
  };
23341
- _proto._projMatChange = function _projMatChange() {
23342
- this._isFrustumProjectDirty = true;
23399
+ _proto._viewMatrixChange = function _viewMatrixChange() {
23400
+ this._isViewMatrixDirty.flag = true;
23401
+ this._isInvViewProjDirty.flag = true;
23402
+ this._frustumChangeFlag.flag = true;
23403
+ };
23404
+ _proto._projectionMatrixChange = function _projectionMatrixChange() {
23343
23405
  this._isProjectionDirty = true;
23344
23406
  this._isInvProjMatDirty = true;
23345
23407
  this._isInvViewProjDirty.flag = true;
23408
+ this._frustumChangeFlag.flag = true;
23346
23409
  };
23347
23410
  _proto._innerViewportToWorldPoint = function _innerViewportToWorldPoint(x, y, z, invViewProjMat, out) {
23348
23411
  // Depth is a normalized value, 0 is nearPlane, 1 is farClipPlane.
@@ -23385,7 +23448,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23385
23448
  _proto._onPixelViewportChanged = function _onPixelViewportChanged() {
23386
23449
  this._updatePixelViewport();
23387
23450
  var _this__customAspectRatio;
23388
- (_this__customAspectRatio = this._customAspectRatio) != null ? _this__customAspectRatio : this._projMatChange();
23451
+ (_this__customAspectRatio = this._customAspectRatio) != null ? _this__customAspectRatio : this._projectionMatrixChange();
23389
23452
  };
23390
23453
  _create_class(Camera1, [
23391
23454
  {
@@ -23405,7 +23468,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23405
23468
  },
23406
23469
  set: function set(value) {
23407
23470
  this._nearClipPlane = value;
23408
- this._projMatChange();
23471
+ this._projectionMatrixChange();
23409
23472
  }
23410
23473
  },
23411
23474
  {
@@ -23417,7 +23480,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23417
23480
  },
23418
23481
  set: function set(value) {
23419
23482
  this._farClipPlane = value;
23420
- this._projMatChange();
23483
+ this._projectionMatrixChange();
23421
23484
  }
23422
23485
  },
23423
23486
  {
@@ -23429,7 +23492,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23429
23492
  },
23430
23493
  set: function set(value) {
23431
23494
  this._fieldOfView = value;
23432
- this._projMatChange();
23495
+ this._projectionMatrixChange();
23433
23496
  }
23434
23497
  },
23435
23498
  {
@@ -23444,7 +23507,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23444
23507
  },
23445
23508
  set: function set(value) {
23446
23509
  this._customAspectRatio = value;
23447
- this._projMatChange();
23510
+ this._projectionMatrixChange();
23448
23511
  }
23449
23512
  },
23450
23513
  {
@@ -23496,7 +23559,12 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23496
23559
  },
23497
23560
  set: function set(value) {
23498
23561
  this._virtualCamera.isOrthographic = value;
23499
- this._projMatChange();
23562
+ this._projectionMatrixChange();
23563
+ if (value) {
23564
+ this.shaderData.enableMacro("CAMERA_ORTHOGRAPHIC");
23565
+ } else {
23566
+ this.shaderData.disableMacro("CAMERA_ORTHOGRAPHIC");
23567
+ }
23500
23568
  }
23501
23569
  },
23502
23570
  {
@@ -23508,7 +23576,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23508
23576
  },
23509
23577
  set: function set(value) {
23510
23578
  this._orthographicSize = value;
23511
- this._projMatChange();
23579
+ this._projectionMatrixChange();
23512
23580
  }
23513
23581
  },
23514
23582
  {
@@ -23517,22 +23585,31 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23517
23585
  * View matrix.
23518
23586
  */ function get() {
23519
23587
  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
- }
23588
+ if (!this._isViewMatrixDirty.flag || this._isCustomViewMatrix) {
23589
+ return viewMatrix;
23590
+ }
23591
+ this._isViewMatrixDirty.flag = false;
23592
+ // Ignore scale
23593
+ var transform = this._transform;
23594
+ miniprogram.Matrix.rotationTranslation(transform.worldRotationQuaternion, transform.worldPosition, viewMatrix);
23595
+ viewMatrix.invert();
23527
23596
  return viewMatrix;
23597
+ },
23598
+ set: function set(value) {
23599
+ this._virtualCamera.viewMatrix.copyFrom(value);
23600
+ this._isCustomViewMatrix = true;
23601
+ this._viewMatrixChange();
23528
23602
  }
23529
23603
  },
23530
23604
  {
23531
23605
  key: "projectionMatrix",
23532
- get: function get() {
23606
+ get: /**
23607
+ * The projection matrix is ​​calculated by the relevant parameters of the camera by default.
23608
+ * If it is manually set, the manual value will be maintained. Call resetProjectionMatrix() to restore it.
23609
+ */ function get() {
23533
23610
  var virtualCamera = this._virtualCamera;
23534
23611
  var projectionMatrix = virtualCamera.projectionMatrix;
23535
- if (!this._isProjectionDirty || this._isProjMatSetting) {
23612
+ if (!this._isProjectionDirty || this._isCustomProjectionMatrix) {
23536
23613
  return projectionMatrix;
23537
23614
  }
23538
23615
  this._isProjectionDirty = false;
@@ -23546,13 +23623,10 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23546
23623
  }
23547
23624
  return projectionMatrix;
23548
23625
  },
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) {
23626
+ set: function set(value) {
23553
23627
  this._virtualCamera.projectionMatrix.copyFrom(value);
23554
- this._isProjMatSetting = true;
23555
- this._projMatChange();
23628
+ this._isCustomProjectionMatrix = true;
23629
+ this._projectionMatrixChange();
23556
23630
  }
23557
23631
  },
23558
23632
  {
@@ -23613,7 +23687,7 @@ __decorate([
23613
23687
  ], exports.Camera.prototype, "_cameraIndex", void 0);
23614
23688
  __decorate([
23615
23689
  ignoreClone
23616
- ], exports.Camera.prototype, "_frustumViewChangeFlag", void 0);
23690
+ ], exports.Camera.prototype, "_frustumChangeFlag", void 0);
23617
23691
  __decorate([
23618
23692
  ignoreClone
23619
23693
  ], exports.Camera.prototype, "_transform", void 0);
@@ -25246,6 +25320,7 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
25246
25320
  _this = EngineObject1.call(this, null) || this;
25247
25321
  _this.name = name;
25248
25322
  _this./** @internal */ _curveBindings = [];
25323
+ _this./** @internal */ _updateFlagManager = new UpdateFlagManager();
25249
25324
  _this._length = 0;
25250
25325
  _this._events = [];
25251
25326
  return _this;
@@ -25273,11 +25348,13 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
25273
25348
  while(--index >= 0 && eventTime < events[index].time);
25274
25349
  events.splice(index + 1, 0, newEvent);
25275
25350
  }
25351
+ this._updateFlagManager.dispatch();
25276
25352
  };
25277
25353
  /**
25278
25354
  * Clears all events from the clip.
25279
25355
  */ _proto.clearEvents = function clearEvents() {
25280
25356
  this._events.length = 0;
25357
+ this._updateFlagManager.dispatch();
25281
25358
  };
25282
25359
  _proto.addCurveBinding = function addCurveBinding(entityPath, componentType, propertyOrSetPropertyPathOrComponentIndex, curveOrSetPropertyPathOrGetPropertyPath, curveOrGetPropertyPath, curve) {
25283
25360
  var curveBinding = new AnimationClipCurveBinding();
@@ -26834,26 +26911,31 @@ exports.AnimatorLayerBlendingMode = void 0;
26834
26911
  }
26835
26912
  };
26836
26913
  _proto._saveAnimatorEventHandlers = function _saveAnimatorEventHandlers(state, animatorStateData) {
26914
+ var _this = this;
26837
26915
  var eventHandlerPool = this._animationEventHandlerPool;
26838
26916
  var scripts = [];
26839
- this._entity.getComponents(Script, scripts);
26840
- var scriptCount = scripts.length;
26841
26917
  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);
26918
+ var clipChangedListener = function() {
26919
+ _this._entity.getComponents(Script, scripts);
26920
+ var scriptCount = scripts.length;
26921
+ var events = state.clip.events;
26922
+ eventHandlers.length = 0;
26923
+ for(var i = 0, n = events.length; i < n; i++){
26924
+ var event = events[i];
26925
+ var eventHandler = eventHandlerPool.getFromPool();
26926
+ var funcName = event.functionName;
26927
+ var handlers = eventHandler.handlers;
26928
+ eventHandler.event = event;
26929
+ handlers.length = 0;
26930
+ for(var j = scriptCount - 1; j >= 0; j--){
26931
+ var handler = scripts[j][funcName];
26932
+ handler && handlers.push(handler);
26933
+ }
26934
+ eventHandlers.push(eventHandler);
26854
26935
  }
26855
- eventHandlers.push(eventHandler);
26856
- }
26936
+ };
26937
+ clipChangedListener();
26938
+ state._updateFlagManager.addListener(clipChangedListener);
26857
26939
  };
26858
26940
  _proto._clearCrossData = function _clearCrossData(animatorLayerData) {
26859
26941
  animatorLayerData.crossCurveMark++;
@@ -27464,9 +27546,11 @@ __decorate([
27464
27546
  this./** @internal */ _onStateEnterScripts = [];
27465
27547
  this./** @internal */ _onStateUpdateScripts = [];
27466
27548
  this./** @internal */ _onStateExitScripts = [];
27549
+ this./** @internal */ _updateFlagManager = new UpdateFlagManager();
27467
27550
  this._clipStartTime = 0;
27468
27551
  this._clipEndTime = 1;
27469
27552
  this._transitions = [];
27553
+ this._onClipChanged = this._onClipChanged.bind(this);
27470
27554
  }
27471
27555
  var _proto = AnimatorState.prototype;
27472
27556
  /**
@@ -27540,6 +27624,11 @@ __decorate([
27540
27624
  index2 !== -1 && this._onStateExitScripts.splice(index2, 1);
27541
27625
  }
27542
27626
  };
27627
+ /**
27628
+ * @internal
27629
+ */ _proto._onClipChanged = function _onClipChanged() {
27630
+ this._updateFlagManager.dispatch();
27631
+ };
27543
27632
  _create_class(AnimatorState, [
27544
27633
  {
27545
27634
  key: "transitions",
@@ -27557,8 +27646,17 @@ __decorate([
27557
27646
  return this._clip;
27558
27647
  },
27559
27648
  set: function set(clip) {
27649
+ var lastClip = this._clip;
27650
+ if (lastClip === clip) {
27651
+ return;
27652
+ }
27653
+ if (lastClip) {
27654
+ lastClip._updateFlagManager.removeListener(this._onClipChanged);
27655
+ }
27560
27656
  this._clip = clip;
27561
27657
  this._clipEndTime = Math.min(this._clipEndTime, 1);
27658
+ this._onClipChanged();
27659
+ clip._updateFlagManager.addListener(this._onClipChanged);
27562
27660
  }
27563
27661
  },
27564
27662
  {