@galacean/engine-core 1.1.0-alpha.2 → 1.1.0-alpha.3

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.
@@ -2766,6 +2766,8 @@ exports.DependentMode = void 0;
2766
2766
  function DisorderedArray(count) {
2767
2767
  if (count === void 0) count = 0;
2768
2768
  this.length = 0;
2769
+ this._isLooping = false;
2770
+ this._blankCount = 0;
2769
2771
  this._elements = new Array(count);
2770
2772
  }
2771
2773
  var _proto = DisorderedArray.prototype;
@@ -2794,21 +2796,49 @@ exports.DependentMode = void 0;
2794
2796
  }
2795
2797
  return this._elements[index];
2796
2798
  };
2799
+ _proto.startLoop = function startLoop() {
2800
+ this._isLooping = true;
2801
+ };
2797
2802
  /**
2798
2803
  * Delete the element at the specified index.
2799
2804
  * @param index - The index of the element to be deleted
2800
2805
  * @returns The replaced item is used to reset its index
2801
2806
  */ _proto.deleteByIndex = function deleteByIndex(index) {
2802
2807
  var elements = this._elements;
2803
- var end = null;
2804
- var lastIndex = this.length - 1;
2805
- if (index !== lastIndex) {
2806
- end = elements[lastIndex];
2807
- elements[index] = end;
2808
+ var end;
2809
+ if (this._isLooping) {
2810
+ this._elements[index] = null;
2811
+ this._blankCount++;
2812
+ } else {
2813
+ var endIndex = this.length - 1;
2814
+ if (index !== endIndex) {
2815
+ end = elements[endIndex];
2816
+ elements[index] = end;
2817
+ }
2818
+ elements[endIndex] = null;
2819
+ this.length--;
2808
2820
  }
2809
- this.length--;
2810
2821
  return end;
2811
2822
  };
2823
+ _proto.endLoop = function endLoop() {
2824
+ this._isLooping = false;
2825
+ if (this._blankCount) {
2826
+ var elements = this._elements;
2827
+ for(var i = 0, j = 0, n = this.length; i < n; i++){
2828
+ var element = elements[i];
2829
+ if (element) {
2830
+ elements[j++] = element;
2831
+ }
2832
+ }
2833
+ this.length -= this._blankCount;
2834
+ this._blankCount = 0;
2835
+ }
2836
+ };
2837
+ _proto.endLoopAndClear = function endLoopAndClear() {
2838
+ this._isLooping = false;
2839
+ this.length = 0;
2840
+ this._blankCount = 0;
2841
+ };
2812
2842
  _proto.garbageCollection = function garbageCollection() {
2813
2843
  this._elements.length = this.length;
2814
2844
  };
@@ -4045,11 +4075,13 @@ var ComponentCloner = /*#__PURE__*/ function() {
4045
4075
  if (!this._isActiveInHierarchy) {
4046
4076
  child._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
4047
4077
  }
4048
- if (this._isActiveInScene) {
4049
- // cross scene should inActive first and then active
4050
- child._isActiveInScene && oldScene !== newScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
4051
- } else {
4052
- child._isActiveInScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
4078
+ if (child._isActiveInScene) {
4079
+ if (this._isActiveInScene) {
4080
+ // Cross scene should inActive first and then active
4081
+ oldScene !== newScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
4082
+ } else {
4083
+ inActiveChangeFlag |= ActiveChangeFlag.Scene;
4084
+ }
4053
4085
  }
4054
4086
  inActiveChangeFlag && child._processInActive(inActiveChangeFlag);
4055
4087
  if (child._scene !== newScene) {
@@ -5022,7 +5054,7 @@ var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission
5022
5054
 
5023
5055
  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
5024
5056
 
5025
- 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]))continue;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]))continue;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]))continue;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
5057
+ 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
5026
5058
 
5027
5059
  var noise_cellular = "#define GLSLIFY 1\n#include <noise_cellular_2D>\n#include <noise_cellular_3D>\n#include <noise_cellular_2x2>\n#include <noise_cellular_2x2x2>\n"; // eslint-disable-line
5028
5060
 
@@ -5062,7 +5094,7 @@ var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecula
5062
5094
 
5063
5095
  var brdf = "#define GLSLIFY 1\nfloat F_Schlick(float dotLH){return 0.04+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);}float 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);}vec3 BRDF_Specular_GGX(vec3 incidentDirection,vec3 viewDir,vec3 normal,vec3 specularColor,float roughness){float alpha=pow2(roughness);vec3 halfDir=normalize(incidentDirection+viewDir);float dotNL=saturate(dot(normal,incidentDirection));float dotNV=saturate(dot(normal,viewDir));float dotNH=saturate(dot(normal,halfDir));float dotLH=saturate(dot(incidentDirection,halfDir));vec3 F=F_Schlick(specularColor,dotLH);float G=G_GGX_SmithCorrelated(alpha,dotNL,dotNV);float D=D_GGX(alpha,dotNH);return F*(G*D);}vec3 BRDF_Diffuse_Lambert(vec3 diffuseColor){return RECIPROCAL_PI*diffuseColor;}"; // eslint-disable-line
5064
5096
 
5065
- var direct_irradiance_frag_define = "#define GLSLIFY 1\n#include <ShadowFragmentDeclaration>\nvoid addDirectRadiance(vec3 incidentDirection,vec3 color,Geometry geometry,Material material,inout ReflectedLight reflectedLight){float attenuation=1.0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoatDotNL=saturate(dot(geometry.clearCoatNormal,incidentDirection));vec3 clearCoatIrradiance=clearCoatDotNL*color;reflectedLight.directSpecular+=material.clearCoat*clearCoatIrradiance*BRDF_Specular_GGX(incidentDirection,geometry.viewDir,geometry.clearCoatNormal,vec3(0.04),material.clearCoatRoughness);attenuation-=material.clearCoat*F_Schlick(geometry.clearCoatDotNV);\n#endif\nfloat dotNL=saturate(dot(geometry.normal,incidentDirection));vec3 irradiance=dotNL*color*PI;reflectedLight.directSpecular+=attenuation*irradiance*BRDF_Specular_GGX(incidentDirection,geometry.viewDir,geometry.normal,material.specularColor,material.roughness);reflectedLight.directDiffuse+=attenuation*irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);}\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nvoid addDirectionalDirectLightRadiance(DirectLight directionalLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 color=directionalLight.color;vec3 direction=-directionalLight.direction;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nvoid addPointDirectLightRadiance(PointLight pointLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=pointLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);vec3 color=pointLight.color;color*=clamp(1.0-pow(lightDistance/pointLight.distance,4.0),0.0,1.0);addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nvoid addSpotDirectLightRadiance(SpotLight spotLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=spotLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);float angleCos=dot(direction,-spotLight.direction);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayEffect=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);vec3 color=spotLight.color;color*=spotEffect*decayEffect;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\nvoid addTotalDirectRadiance(Geometry geometry,Material material,inout ReflectedLight reflectedLight){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]))continue;directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==0){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];addDirectionalDirectLightRadiance(directionalLight,geometry,material,reflectedLight);}\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]))continue;pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];addPointDirectLightRadiance(pointLight,geometry,material,reflectedLight);}\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]))continue;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];addSpotDirectLightRadiance(spotLight,geometry,material,reflectedLight);}\n#endif\n}"; // eslint-disable-line
5097
+ var direct_irradiance_frag_define = "#define GLSLIFY 1\n#include <ShadowFragmentDeclaration>\nvoid addDirectRadiance(vec3 incidentDirection,vec3 color,Geometry geometry,Material material,inout ReflectedLight reflectedLight){float attenuation=1.0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoatDotNL=saturate(dot(geometry.clearCoatNormal,incidentDirection));vec3 clearCoatIrradiance=clearCoatDotNL*color;reflectedLight.directSpecular+=material.clearCoat*clearCoatIrradiance*BRDF_Specular_GGX(incidentDirection,geometry.viewDir,geometry.clearCoatNormal,vec3(0.04),material.clearCoatRoughness);attenuation-=material.clearCoat*F_Schlick(geometry.clearCoatDotNV);\n#endif\nfloat dotNL=saturate(dot(geometry.normal,incidentDirection));vec3 irradiance=dotNL*color*PI;reflectedLight.directSpecular+=attenuation*irradiance*BRDF_Specular_GGX(incidentDirection,geometry.viewDir,geometry.normal,material.specularColor,material.roughness);reflectedLight.directDiffuse+=attenuation*irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);}\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nvoid addDirectionalDirectLightRadiance(DirectLight directionalLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 color=directionalLight.color;vec3 direction=-directionalLight.direction;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nvoid addPointDirectLightRadiance(PointLight pointLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=pointLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);vec3 color=pointLight.color;color*=clamp(1.0-pow(lightDistance/pointLight.distance,4.0),0.0,1.0);addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nvoid addSpotDirectLightRadiance(SpotLight spotLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=spotLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);float angleCos=dot(direction,-spotLight.direction);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayEffect=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);vec3 color=spotLight.color;color*=spotEffect*decayEffect;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\nvoid addTotalDirectRadiance(Geometry geometry,Material material,inout ReflectedLight reflectedLight){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];addDirectionalDirectLightRadiance(directionalLight,geometry,material,reflectedLight);}}\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];addPointDirectLightRadiance(pointLight,geometry,material,reflectedLight);}}\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];addSpotDirectLightRadiance(spotLight,geometry,material,reflectedLight);}}\n#endif\n}"; // eslint-disable-line
5066
5098
 
5067
5099
  var ibl_frag_define = "#define GLSLIFY 1\nvec3 getLightProbeIrradiance(vec3 sh[9],vec3 normal){normal.x=-normal.x;vec3 result=sh[0]+sh[1]*(normal.y)+sh[2]*(normal.z)+sh[3]*(normal.x)+sh[4]*(normal.y*normal.x)+sh[5]*(normal.y*normal.z)+sh[6]*(3.0*normal.z*normal.z-1.0)+sh[7]*(normal.z*normal.x)+sh[8]*(normal.x*normal.x-normal.y*normal.y);return max(result,vec3(0.0));}vec3 envBRDFApprox(vec3 specularColor,float roughness,float dotNV){const vec4 c0=vec4(-1,-0.0275,-0.572,0.022);const vec4 c1=vec4(1,0.0425,1.04,-0.04);vec4 r=roughness*c0+c1;float a004=min(r.x*r.x,exp2(-9.28*dotNV))*r.x+r.y;vec2 AB=vec2(-1.04,1.04)*a004+r.zw;return specularColor*AB.x+AB.y;}float getSpecularMIPLevel(float roughness,int maxMIPLevel){return roughness*float(maxMIPLevel);}vec3 getLightProbeRadiance(vec3 viewDir,vec3 normal,float roughness,int maxMIPLevel,float specularIntensity){\n#ifndef SCENE_USE_SPECULAR_ENV\nreturn vec3(0);\n#else\nvec3 reflectVec=reflect(-viewDir,normal);reflectVec.x=-reflectVec.x;float specularMIPLevel=getSpecularMIPLevel(roughness,maxMIPLevel);\n#ifdef HAS_TEX_LOD\nvec4 envMapColor=textureCubeLodEXT(scene_EnvSpecularSampler,reflectVec,specularMIPLevel);\n#else\nvec4 envMapColor=textureCube(scene_EnvSpecularSampler,reflectVec,specularMIPLevel);\n#endif\n#ifdef SCENE_IS_DECODE_ENV_RGBM\nenvMapColor.rgb=RGBMToLinear(envMapColor,5.0).rgb;\n#ifdef ENGINE_IS_COLORSPACE_GAMMA\nenvMapColor=linearToGamma(envMapColor);\n#endif\n#else\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nenvMapColor=gammaToLinear(envMapColor);\n#endif\n#endif\nreturn envMapColor.rgb*specularIntensity;\n#endif\n}"; // eslint-disable-line
5068
5100
 
@@ -11557,19 +11589,20 @@ var PrimitiveType;
11557
11589
  /**
11558
11590
  * @internal
11559
11591
  */ _proto.update = function update() {
11560
- var skin = this._skin;
11561
- if (skin) {
11562
- var ibms = skin.inverseBindMatrices;
11563
- var worldToLocal = this._rootBone.getInvModelMatrix();
11564
- var _this = this, bones = _this._bones, jointMatrices = _this._jointMatrices;
11592
+ var _this = this, skin = _this._skin, bones = _this._bones;
11593
+ if (skin && bones) {
11565
11594
  // @todo: can optimize when share skin
11595
+ var jointMatrices = this._jointMatrices;
11596
+ var bindMatrices = skin.inverseBindMatrices;
11597
+ var _this__rootBone;
11598
+ var worldToLocal = ((_this__rootBone = this._rootBone) != null ? _this__rootBone : this.entity).getInvModelMatrix();
11566
11599
  for(var i = bones.length - 1; i >= 0; i--){
11567
11600
  var bone = bones[i];
11568
11601
  var offset = i * 16;
11569
11602
  if (bone) {
11570
- Utils._floatMatrixMultiply(bone.transform.worldMatrix, ibms[i].elements, 0, jointMatrices, offset);
11603
+ Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, jointMatrices, offset);
11571
11604
  } else {
11572
- jointMatrices.set(ibms[i].elements, offset);
11605
+ jointMatrices.set(bindMatrices[i].elements, offset);
11573
11606
  }
11574
11607
  Utils._floatMatrixMultiply(worldToLocal, jointMatrices, offset, jointMatrices, offset);
11575
11608
  }
@@ -12240,6 +12273,41 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
12240
12273
  return TextRenderData;
12241
12274
  }(RenderData);
12242
12275
 
12276
+ /**
12277
+ * Asset Type.
12278
+ */ exports.AssetType = void 0;
12279
+ (function(AssetType) {
12280
+ AssetType[/**
12281
+ * Plain text.
12282
+ * @remarks Will not be cached based on url in ResourceManager.
12283
+ */ "Text"] = "Text";
12284
+ AssetType[/**
12285
+ * JSON.
12286
+ * @remarks Will not be cached based on url in ResourceManager.
12287
+ */ "JSON"] = "JSON";
12288
+ AssetType[/**
12289
+ * ArrayBuffer.
12290
+ * @remarks Will not be cached based on url in ResourceManager.
12291
+ */ "Buffer"] = "Buffer";
12292
+ AssetType[/** 2D Texture. */ "Texture2D"] = "Texture2D";
12293
+ AssetType[/** Cube Texture. */ "TextureCube"] = "TextureCube";
12294
+ AssetType[/** Material. */ "Material"] = "Material";
12295
+ AssetType[/** Mesh. */ "Mesh"] = "Mesh";
12296
+ AssetType[/** AnimationClip. */ "AnimationClip"] = "AnimationClip";
12297
+ AssetType[/** AnimatorController. */ "AnimatorController"] = "AnimatorController";
12298
+ AssetType[/** Prefab.*/ "GLTF"] = "GLTF";
12299
+ AssetType[/** Compress Texture. */ "KTX"] = "KTX";
12300
+ AssetType[/** Cube Compress Texture. */ "KTXCube"] = "KTXCube";
12301
+ AssetType[/** KTX2 Compress Texture */ "KTX2"] = "KTX2";
12302
+ AssetType[/** Sprite. */ "Sprite"] = "Sprite";
12303
+ AssetType[/** Sprite Atlas. */ "SpriteAtlas"] = "SpriteAtlas";
12304
+ AssetType[/** Ambient light. */ "Env"] = "Environment";
12305
+ AssetType[/** Scene. */ "Scene"] = "Scene";
12306
+ AssetType[/** HDR to cube. */ "HDR"] = "HDR";
12307
+ AssetType[/** Font. */ "Font"] = "Font";
12308
+ AssetType[/** Source Font, include ttf、 otf and woff. */ "SourceFont"] = "SourceFont";
12309
+ })(exports.AssetType || (exports.AssetType = {}));
12310
+
12243
12311
  var SafeLoopArray = /*#__PURE__*/ function() {
12244
12312
  function SafeLoopArray() {
12245
12313
  this._array = [];
@@ -12352,10 +12420,13 @@ var SafeLoopArray = /*#__PURE__*/ function() {
12352
12420
  */ _proto.loadScene = function loadScene(url, destroyOldScene) {
12353
12421
  if (destroyOldScene === void 0) destroyOldScene = true;
12354
12422
  var _this = this;
12355
- var scenePromise = this.engine.resourceManager.load(url);
12423
+ var scenePromise = this.engine.resourceManager.load({
12424
+ url: url,
12425
+ type: exports.AssetType.Scene
12426
+ });
12356
12427
  scenePromise.then(function(scene) {
12357
- var scenes = _this._scenes;
12358
12428
  if (destroyOldScene) {
12429
+ var scenes = _this._scenes.getArray();
12359
12430
  for(var i = 0, n = scenes.length; i < n; i++){
12360
12431
  scenes[i].destroy();
12361
12432
  }
@@ -12985,17 +13056,21 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
12985
13056
  if (this._currentEnteredEntity !== rayCastEntity) {
12986
13057
  if (this._currentEnteredEntity) {
12987
13058
  var scripts = this._currentEnteredEntity._scripts;
12988
- for(var i = scripts.length - 1; i >= 0; i--){
12989
- var script = scripts.get(i);
12990
- script._waitHandlingInValid || script.onPointerExit(this);
13059
+ scripts.startLoop();
13060
+ for(var i = 0; i < scripts.length; i++){
13061
+ var _scripts_get;
13062
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onPointerExit(this);
12991
13063
  }
13064
+ scripts.endLoop();
12992
13065
  }
12993
13066
  if (rayCastEntity) {
12994
13067
  var scripts1 = rayCastEntity._scripts;
12995
- for(var i1 = scripts1.length - 1; i1 >= 0; i1--){
12996
- var script1 = scripts1.get(i1);
12997
- script1._waitHandlingInValid || script1.onPointerEnter(this);
13068
+ scripts1.startLoop();
13069
+ for(var i1 = 0; i1 < scripts1.length; i1++){
13070
+ var _scripts_get1;
13071
+ (_scripts_get1 = scripts1.get(i1)) == null ? void 0 : _scripts_get1.onPointerEnter(this);
12998
13072
  }
13073
+ scripts1.endLoop();
12999
13074
  }
13000
13075
  this._currentEnteredEntity = rayCastEntity;
13001
13076
  }
@@ -13005,10 +13080,12 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
13005
13080
  */ _proto._firePointerDown = function _firePointerDown(rayCastEntity) {
13006
13081
  if (rayCastEntity) {
13007
13082
  var scripts = rayCastEntity._scripts;
13008
- for(var i = scripts.length - 1; i >= 0; i--){
13009
- var script = scripts.get(i);
13010
- script._waitHandlingInValid || script.onPointerDown(this);
13083
+ scripts.startLoop();
13084
+ for(var i = 0; i < scripts.length; i++){
13085
+ var _scripts_get;
13086
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onPointerDown(this);
13011
13087
  }
13088
+ scripts.endLoop();
13012
13089
  }
13013
13090
  this._currentPressedEntity = rayCastEntity;
13014
13091
  };
@@ -13017,10 +13094,12 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
13017
13094
  */ _proto._firePointerDrag = function _firePointerDrag() {
13018
13095
  if (this._currentPressedEntity) {
13019
13096
  var scripts = this._currentPressedEntity._scripts;
13020
- for(var i = scripts.length - 1; i >= 0; i--){
13021
- var script = scripts.get(i);
13022
- script._waitHandlingInValid || script.onPointerDrag(this);
13097
+ scripts.startLoop();
13098
+ for(var i = 0; i < scripts.length; i++){
13099
+ var _scripts_get;
13100
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onPointerDrag(this);
13023
13101
  }
13102
+ scripts.endLoop();
13024
13103
  }
13025
13104
  };
13026
13105
  /**
@@ -13030,13 +13109,15 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
13030
13109
  if (pressedEntity) {
13031
13110
  var sameTarget = pressedEntity === rayCastEntity;
13032
13111
  var scripts = pressedEntity._scripts;
13033
- for(var i = scripts.length - 1; i >= 0; i--){
13112
+ scripts.startLoop();
13113
+ for(var i = 0; i < scripts.length; i++){
13034
13114
  var script = scripts.get(i);
13035
- if (!script._waitHandlingInValid) {
13115
+ if (script) {
13036
13116
  sameTarget && script.onPointerClick(this);
13037
13117
  script.onPointerUp(this);
13038
13118
  }
13039
13119
  }
13120
+ scripts.endLoop();
13040
13121
  this._currentPressedEntity = null;
13041
13122
  }
13042
13123
  };
@@ -13640,114 +13721,138 @@ var Collision = function Collision() {
13640
13721
  var shape1 = physicalObjectsMap[obj1];
13641
13722
  var shape2 = physicalObjectsMap[obj2];
13642
13723
  var scripts = shape1.collider.entity._scripts;
13643
- for(var i = 0, len = scripts.length; i < len; i++){
13724
+ scripts.startLoop();
13725
+ for(var i = 0; i < scripts.length; i++){
13644
13726
  var script = scripts.get(i);
13645
- if (!script._waitHandlingInValid) {
13727
+ if (script) {
13646
13728
  var collision = PhysicsScene._collision;
13647
13729
  collision.shape = shape2;
13648
13730
  script.onCollisionEnter(collision);
13649
13731
  }
13650
13732
  }
13733
+ scripts.endLoop();
13651
13734
  scripts = shape2.collider.entity._scripts;
13652
- for(var i1 = 0, len1 = scripts.length; i1 < len1; i1++){
13735
+ scripts.startLoop();
13736
+ for(var i1 = 0; i1 < scripts.length; i1++){
13653
13737
  var script1 = scripts.get(i1);
13654
- if (!script1._waitHandlingInValid) {
13738
+ if (script1) {
13655
13739
  var collision1 = PhysicsScene._collision;
13656
13740
  collision1.shape = shape1;
13657
13741
  script1.onCollisionEnter(collision1);
13658
13742
  }
13659
13743
  }
13744
+ scripts.endLoop();
13660
13745
  };
13661
13746
  this._onContactExit = function(obj1, obj2) {
13662
13747
  var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
13663
13748
  var shape1 = physicalObjectsMap[obj1];
13664
13749
  var shape2 = physicalObjectsMap[obj2];
13665
13750
  var scripts = shape1.collider.entity._scripts;
13666
- for(var i = 0, len = scripts.length; i < len; i++){
13751
+ scripts.startLoop();
13752
+ for(var i = 0; i < scripts.length; i++){
13667
13753
  var script = scripts.get(i);
13668
- if (!script._waitHandlingInValid) {
13754
+ if (script) {
13669
13755
  var collision = PhysicsScene._collision;
13670
13756
  collision.shape = shape2;
13671
13757
  script.onCollisionExit(collision);
13672
13758
  }
13673
13759
  }
13760
+ scripts.endLoop();
13674
13761
  scripts = shape2.collider.entity._scripts;
13675
- for(var i1 = 0, len1 = scripts.length; i1 < len1; i1++){
13762
+ scripts.startLoop();
13763
+ for(var i1 = 0; i1 < scripts.length; i1++){
13676
13764
  var script1 = scripts.get(i1);
13677
- if (!script1._waitHandlingInValid) {
13765
+ if (script1) {
13678
13766
  var collision1 = PhysicsScene._collision;
13679
13767
  collision1.shape = shape1;
13680
13768
  script1.onCollisionExit(collision1);
13681
13769
  }
13682
13770
  }
13771
+ scripts.endLoop();
13683
13772
  };
13684
13773
  this._onContactStay = function(obj1, obj2) {
13685
13774
  var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
13686
13775
  var shape1 = physicalObjectsMap[obj1];
13687
13776
  var shape2 = physicalObjectsMap[obj2];
13688
13777
  var scripts = shape1.collider.entity._scripts;
13689
- for(var i = 0, len = scripts.length; i < len; i++){
13778
+ scripts.startLoop();
13779
+ for(var i = 0; i < scripts.length; i++){
13690
13780
  var script = scripts.get(i);
13691
- if (!script._waitHandlingInValid) {
13781
+ if (script) {
13692
13782
  var collision = PhysicsScene._collision;
13693
13783
  collision.shape = shape2;
13694
13784
  script.onCollisionStay(collision);
13695
13785
  }
13696
13786
  }
13787
+ scripts.endLoop();
13697
13788
  scripts = shape2.collider.entity._scripts;
13698
- for(var i1 = 0, len1 = scripts.length; i1 < len1; i1++){
13789
+ scripts.startLoop();
13790
+ for(var i1 = 0; i1 < scripts.length; i1++){
13699
13791
  var script1 = scripts.get(i1);
13700
- if (!script1._waitHandlingInValid) {
13792
+ if (script1) {
13701
13793
  var collision1 = PhysicsScene._collision;
13702
13794
  collision1.shape = shape1;
13703
13795
  script1.onCollisionStay(collision1);
13704
13796
  }
13705
13797
  }
13798
+ scripts.endLoop();
13706
13799
  };
13707
13800
  this._onTriggerEnter = function(obj1, obj2) {
13708
13801
  var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
13709
13802
  var shape1 = physicalObjectsMap[obj1];
13710
13803
  var shape2 = physicalObjectsMap[obj2];
13711
13804
  var scripts = shape1.collider.entity._scripts;
13712
- for(var i = 0, len = scripts.length; i < len; i++){
13713
- var script = scripts.get(i);
13714
- script._waitHandlingInValid || script.onTriggerEnter(shape2);
13805
+ scripts.startLoop();
13806
+ for(var i = 0; i < scripts.length; i++){
13807
+ var _scripts_get;
13808
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onTriggerEnter(shape2);
13715
13809
  }
13810
+ scripts.endLoop();
13716
13811
  scripts = shape2.collider.entity._scripts;
13717
- for(var i1 = 0, len1 = scripts.length; i1 < len1; i1++){
13718
- var script1 = scripts.get(i1);
13719
- script1._waitHandlingInValid || script1.onTriggerEnter(shape1);
13812
+ scripts.startLoop();
13813
+ for(var i1 = 0; i1 < scripts.length; i1++){
13814
+ var _scripts_get1;
13815
+ (_scripts_get1 = scripts.get(i1)) == null ? void 0 : _scripts_get1.onTriggerEnter(shape1);
13720
13816
  }
13817
+ scripts.endLoop();
13721
13818
  };
13722
13819
  this._onTriggerExit = function(obj1, obj2) {
13723
13820
  var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
13724
13821
  var shape1 = physicalObjectsMap[obj1];
13725
13822
  var shape2 = physicalObjectsMap[obj2];
13726
13823
  var scripts = shape1.collider.entity._scripts;
13727
- for(var i = 0, n = scripts.length; i < n; i++){
13728
- var script = scripts.get(i);
13729
- script._waitHandlingInValid || script.onTriggerExit(shape2);
13824
+ scripts.startLoop();
13825
+ for(var i = 0; i < scripts.length; i++){
13826
+ var _scripts_get;
13827
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onTriggerExit(shape2);
13730
13828
  }
13829
+ scripts.endLoop();
13731
13830
  scripts = shape2.collider.entity._scripts;
13732
- for(var i1 = 0, n1 = scripts.length; i1 < n1; i1++){
13733
- var script1 = scripts.get(i1);
13734
- script1._waitHandlingInValid || script1.onTriggerExit(shape1);
13831
+ scripts.startLoop();
13832
+ for(var i1 = 0; i1 < scripts.length; i1++){
13833
+ var _scripts_get1;
13834
+ (_scripts_get1 = scripts.get(i1)) == null ? void 0 : _scripts_get1.onTriggerExit(shape1);
13735
13835
  }
13836
+ scripts.endLoop();
13736
13837
  };
13737
13838
  this._onTriggerStay = function(obj1, obj2) {
13738
13839
  var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
13739
13840
  var shape1 = physicalObjectsMap[obj1];
13740
13841
  var shape2 = physicalObjectsMap[obj2];
13741
13842
  var scripts = shape1.collider.entity._scripts;
13742
- for(var i = 0, len = scripts.length; i < len; i++){
13743
- var script = scripts.get(i);
13744
- script._waitHandlingInValid || script.onTriggerStay(shape2);
13843
+ scripts.startLoop();
13844
+ for(var i = 0; i < scripts.length; i++){
13845
+ var _scripts_get;
13846
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onTriggerStay(shape2);
13745
13847
  }
13848
+ scripts.endLoop();
13746
13849
  scripts = shape2.collider.entity._scripts;
13747
- for(var i1 = 0, len1 = scripts.length; i1 < len1; i1++){
13748
- var script1 = scripts.get(i1);
13749
- script1._waitHandlingInValid || script1.onTriggerStay(shape1);
13850
+ scripts.startLoop();
13851
+ for(var i1 = 0; i1 < scripts.length; i1++){
13852
+ var _scripts_get1;
13853
+ (_scripts_get1 = scripts.get(i1)) == null ? void 0 : _scripts_get1.onTriggerStay(shape1);
13750
13854
  }
13855
+ scripts.endLoop();
13751
13856
  };
13752
13857
  this._scene = scene;
13753
13858
  this._setGravity = this._setGravity.bind(this);
@@ -16885,7 +16990,6 @@ ShaderPool.init();
16885
16990
  this._onUpdateScripts = new DisorderedArray();
16886
16991
  this._onLateUpdateScripts = new DisorderedArray();
16887
16992
  this._onPhysicsUpdateScripts = new DisorderedArray();
16888
- this._disableScripts = [];
16889
16993
  this._pendingDestroyScripts = [];
16890
16994
  this._disposeDestroyScripts = [];
16891
16995
  // Animation
@@ -16963,102 +17067,110 @@ ShaderPool.init();
16963
17067
  replaced && (replaced._onUpdateIndex = renderer._onUpdateIndex);
16964
17068
  renderer._onUpdateIndex = -1;
16965
17069
  };
16966
- _proto.addDisableScript = function addDisableScript(component) {
16967
- this._disableScripts.push(component);
16968
- };
16969
17070
  _proto.addPendingDestroyScript = function addPendingDestroyScript(component) {
16970
17071
  this._pendingDestroyScripts.push(component);
16971
17072
  };
16972
17073
  _proto.callScriptOnStart = function callScriptOnStart() {
16973
17074
  var onStartScripts = this._onStartScripts;
16974
17075
  if (onStartScripts.length > 0) {
17076
+ onStartScripts.startLoop();
16975
17077
  var elements = onStartScripts._elements;
16976
17078
  // The 'onStartScripts.length' maybe add if you add some Script with addComponent() in some Script's onStart()
16977
17079
  for(var i = 0; i < onStartScripts.length; i++){
16978
17080
  var script = elements[i];
16979
- if (!script._waitHandlingInValid) {
17081
+ if (script) {
16980
17082
  script._started = true;
16981
- script._onStartIndex = -1;
17083
+ this.removeOnStartScript(script);
16982
17084
  script.onStart();
16983
17085
  }
16984
17086
  }
16985
- onStartScripts.length = 0;
17087
+ onStartScripts.endLoopAndClear();
16986
17088
  }
16987
17089
  };
16988
17090
  _proto.callScriptOnUpdate = function callScriptOnUpdate(deltaTime) {
16989
- var elements = this._onUpdateScripts._elements;
16990
- for(var i = this._onUpdateScripts.length - 1; i >= 0; --i){
17091
+ var onUpdateScripts = this._onUpdateScripts;
17092
+ onUpdateScripts.startLoop();
17093
+ var elements = onUpdateScripts._elements;
17094
+ for(var i = 0; i < onUpdateScripts.length; i++){
16991
17095
  var element = elements[i];
16992
- if (!element._waitHandlingInValid && element._started) {
17096
+ if (element == null ? void 0 : element._started) {
16993
17097
  element.onUpdate(deltaTime);
16994
17098
  }
16995
17099
  }
17100
+ onUpdateScripts.endLoop();
16996
17101
  };
16997
17102
  _proto.callScriptOnLateUpdate = function callScriptOnLateUpdate(deltaTime) {
16998
- var elements = this._onLateUpdateScripts._elements;
16999
- for(var i = this._onLateUpdateScripts.length - 1; i >= 0; --i){
17103
+ var onLateUpdateScripts = this._onLateUpdateScripts;
17104
+ onLateUpdateScripts.startLoop();
17105
+ var elements = onLateUpdateScripts._elements;
17106
+ for(var i = 0; i < onLateUpdateScripts.length; i++){
17000
17107
  var element = elements[i];
17001
- if (!element._waitHandlingInValid && element._started) {
17108
+ if (element == null ? void 0 : element._started) {
17002
17109
  element.onLateUpdate(deltaTime);
17003
17110
  }
17004
17111
  }
17112
+ onLateUpdateScripts.endLoop();
17005
17113
  };
17006
17114
  _proto.callScriptOnPhysicsUpdate = function callScriptOnPhysicsUpdate() {
17007
- var elements = this._onPhysicsUpdateScripts._elements;
17008
- for(var i = this._onPhysicsUpdateScripts.length - 1; i >= 0; --i){
17115
+ var onPhysicsUpdateScripts = this._onPhysicsUpdateScripts;
17116
+ onPhysicsUpdateScripts.startLoop();
17117
+ var elements = onPhysicsUpdateScripts._elements;
17118
+ for(var i = 0; i < onPhysicsUpdateScripts.length; i++){
17009
17119
  var element = elements[i];
17010
- if (!element._waitHandlingInValid && element._started) {
17120
+ if (element == null ? void 0 : element._started) {
17011
17121
  element.onPhysicsUpdate();
17012
17122
  }
17013
17123
  }
17124
+ onPhysicsUpdateScripts.endLoop();
17014
17125
  };
17015
17126
  _proto.callAnimationUpdate = function callAnimationUpdate(deltaTime) {
17016
- var elements = this._onUpdateAnimations._elements;
17017
- for(var i = this._onUpdateAnimations.length - 1; i >= 0; --i){
17127
+ var onUpdateAnimations = this._onUpdateAnimations;
17128
+ onUpdateAnimations.startLoop();
17129
+ var elements = onUpdateAnimations._elements;
17130
+ for(var i = 0; i < onUpdateAnimations.length; i++){
17018
17131
  //@ts-ignore
17019
17132
  elements[i].update(deltaTime);
17020
17133
  }
17134
+ onUpdateAnimations.endLoop();
17021
17135
  };
17022
17136
  _proto.callRendererOnUpdate = function callRendererOnUpdate(deltaTime) {
17023
- var elements = this._onUpdateRenderers._elements;
17024
- for(var i = this._onUpdateRenderers.length - 1; i >= 0; --i){
17137
+ var onUpdateRenderers = this._onUpdateRenderers;
17138
+ onUpdateRenderers.startLoop();
17139
+ var elements = onUpdateRenderers._elements;
17140
+ for(var i = 0; i < onUpdateRenderers.length; i++){
17025
17141
  elements[i].update(deltaTime);
17026
17142
  }
17143
+ onUpdateRenderers.endLoop();
17027
17144
  };
17028
17145
  _proto.handlingInvalidScripts = function handlingInvalidScripts() {
17029
- var _this = this, disableScripts = _this._disableScripts;
17030
- var length = disableScripts.length;
17031
- if (length > 0) {
17032
- for(var i = length - 1; i >= 0; i--){
17033
- var disableScript = disableScripts[i];
17034
- disableScript._waitHandlingInValid && disableScript._handlingInValid();
17035
- }
17036
- disableScripts.length = 0;
17037
- }
17038
- var _this1 = this, pendingDestroyScripts = _this1._disposeDestroyScripts, disposeDestroyScripts = _this1._pendingDestroyScripts;
17146
+ var _this = this, pendingDestroyScripts = _this._disposeDestroyScripts, disposeDestroyScripts = _this._pendingDestroyScripts;
17039
17147
  this._disposeDestroyScripts = disposeDestroyScripts;
17040
17148
  this._pendingDestroyScripts = pendingDestroyScripts;
17041
17149
  length = disposeDestroyScripts.length;
17042
17150
  if (length > 0) {
17043
- for(var i1 = length - 1; i1 >= 0; i1--){
17044
- disposeDestroyScripts[i1].onDestroy();
17151
+ for(var i = length - 1; i >= 0; i--){
17152
+ disposeDestroyScripts[i].onDestroy();
17045
17153
  }
17046
17154
  disposeDestroyScripts.length = 0;
17047
17155
  }
17048
17156
  };
17049
17157
  _proto.callCameraOnBeginRender = function callCameraOnBeginRender(camera) {
17050
17158
  var scripts = camera.entity._scripts;
17051
- for(var i = scripts.length - 1; i >= 0; --i){
17052
- var script = scripts.get(i);
17053
- script._waitHandlingInValid || script.onBeginRender(camera);
17159
+ scripts.startLoop();
17160
+ for(var i = 0; i < scripts.length; i++){
17161
+ var _scripts_get;
17162
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onBeginRender(camera);
17054
17163
  }
17164
+ scripts.endLoop();
17055
17165
  };
17056
17166
  _proto.callCameraOnEndRender = function callCameraOnEndRender(camera) {
17057
17167
  var scripts = camera.entity._scripts;
17058
- for(var i = scripts.length - 1; i >= 0; --i){
17059
- var script = scripts.get(i);
17060
- script._waitHandlingInValid || script.onEndRender(camera);
17168
+ scripts.startLoop();
17169
+ for(var i = 0; i < scripts.length; i++){
17170
+ var _scripts_get;
17171
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onEndRender(camera);
17061
17172
  }
17173
+ scripts.endLoop();
17062
17174
  };
17063
17175
  _proto.getActiveChangedTempList = function getActiveChangedTempList() {
17064
17176
  return this._componentsContainerPool.length ? this._componentsContainerPool.pop() : [];
@@ -18029,19 +18141,20 @@ __decorate([
18029
18141
  }
18030
18142
  // Process entity active/inActive
18031
18143
  var inActiveChangeFlag = ActiveChangeFlag.None;
18032
- if (this._isActiveInEngine) {
18033
- // Cross scene should inActive first and then active
18034
- entity._isActiveInHierarchy && oldScene !== this && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
18035
- } else {
18036
- entity._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
18144
+ if (entity._isActiveInHierarchy) {
18145
+ this._isActiveInEngine || (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
18037
18146
  }
18147
+ // Cross scene should inActive first and then active
18148
+ entity._isActiveInScene && oldScene !== this && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
18038
18149
  inActiveChangeFlag && entity._processInActive(inActiveChangeFlag);
18039
18150
  if (oldScene !== this) {
18040
18151
  Entity._traverseSetOwnerScene(entity, this);
18041
18152
  }
18042
18153
  var activeChangeFlag = ActiveChangeFlag.None;
18043
- if (this._isActiveInEngine && entity._isActive) {
18044
- !entity._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
18154
+ if (entity._isActive) {
18155
+ if (this._isActiveInEngine) {
18156
+ !entity._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
18157
+ }
18045
18158
  (!entity._isActiveInScene || oldScene !== this) && (activeChangeFlag |= ActiveChangeFlag.Scene);
18046
18159
  }
18047
18160
  activeChangeFlag && entity._processActive(activeChangeFlag);
@@ -18397,7 +18510,6 @@ __decorate([
18397
18510
  /** @internal */ _this._onPreRenderIndex = -1;
18398
18511
  /** @internal */ _this._onPostRenderIndex = -1;
18399
18512
  _this._entityScriptsIndex = -1;
18400
- _this._waitHandlingInValid = false;
18401
18513
  return _this;
18402
18514
  }
18403
18515
  var _proto = Script.prototype;
@@ -18506,37 +18618,30 @@ __decorate([
18506
18618
  /**
18507
18619
  * @internal
18508
18620
  */ _proto._onEnableInScene = function _onEnableInScene() {
18509
- if (this._waitHandlingInValid) {
18510
- this._waitHandlingInValid = false;
18511
- } else {
18512
- var _this_scene = this.scene, componentsManager = _this_scene._componentsManager;
18513
- var prototype = Script.prototype;
18514
- if (!this._started) {
18515
- componentsManager.addOnStartScript(this);
18516
- }
18517
- if (this.onUpdate !== prototype.onUpdate) {
18518
- componentsManager.addOnUpdateScript(this);
18519
- }
18520
- if (this.onLateUpdate !== prototype.onLateUpdate) {
18521
- componentsManager.addOnLateUpdateScript(this);
18522
- }
18523
- if (this.onPhysicsUpdate !== prototype.onPhysicsUpdate) {
18524
- componentsManager.addOnPhysicsUpdateScript(this);
18525
- }
18526
- this._entity._addScript(this);
18621
+ var _this_scene = this.scene, componentsManager = _this_scene._componentsManager;
18622
+ var prototype = Script.prototype;
18623
+ if (!this._started) {
18624
+ componentsManager.addOnStartScript(this);
18625
+ }
18626
+ if (this.onUpdate !== prototype.onUpdate) {
18627
+ componentsManager.addOnUpdateScript(this);
18628
+ }
18629
+ if (this.onLateUpdate !== prototype.onLateUpdate) {
18630
+ componentsManager.addOnLateUpdateScript(this);
18631
+ }
18632
+ if (this.onPhysicsUpdate !== prototype.onPhysicsUpdate) {
18633
+ componentsManager.addOnPhysicsUpdateScript(this);
18527
18634
  }
18635
+ this._entity._addScript(this);
18528
18636
  };
18529
18637
  /**
18530
18638
  * @internal
18531
18639
  */ _proto._onDisableInScene = function _onDisableInScene() {
18532
- this._waitHandlingInValid = true;
18533
- this.scene._componentsManager.addDisableScript(this);
18534
- };
18535
- /**
18536
- * @internal
18537
- */ _proto._handlingInValid = function _handlingInValid() {
18538
18640
  var componentsManager = this.scene._componentsManager;
18539
18641
  var prototype = Script.prototype;
18642
+ if (!this._started) {
18643
+ componentsManager.removeOnStartScript(this);
18644
+ }
18540
18645
  if (this.onUpdate !== prototype.onUpdate) {
18541
18646
  componentsManager.removeOnUpdateScript(this);
18542
18647
  }
@@ -18547,7 +18652,6 @@ __decorate([
18547
18652
  componentsManager.removeOnPhysicsUpdateScript(this);
18548
18653
  }
18549
18654
  this._entity._removeScript(this);
18550
- this._waitHandlingInValid = false;
18551
18655
  };
18552
18656
  /**
18553
18657
  * @internal
@@ -18581,9 +18685,6 @@ __decorate([
18581
18685
  __decorate([
18582
18686
  ignoreClone
18583
18687
  ], Script.prototype, "_entityScriptsIndex", void 0);
18584
- __decorate([
18585
- ignoreClone
18586
- ], Script.prototype, "_waitHandlingInValid", void 0);
18587
18688
 
18588
18689
  /**
18589
18690
  * Depth texture mode.
@@ -20898,41 +20999,6 @@ var MultiExecutor = /*#__PURE__*/ function() {
20898
20999
  Loader._engineObjects = {};
20899
21000
  })();
20900
21001
 
20901
- /**
20902
- * Asset Type.
20903
- */ exports.AssetType = void 0;
20904
- (function(AssetType) {
20905
- AssetType[/**
20906
- * Plain text.
20907
- * @remarks Will not be cached based on url in ResourceManager.
20908
- */ "Text"] = "Text";
20909
- AssetType[/**
20910
- * JSON.
20911
- * @remarks Will not be cached based on url in ResourceManager.
20912
- */ "JSON"] = "JSON";
20913
- AssetType[/**
20914
- * ArrayBuffer.
20915
- * @remarks Will not be cached based on url in ResourceManager.
20916
- */ "Buffer"] = "Buffer";
20917
- AssetType[/** 2D Texture. */ "Texture2D"] = "Texture2D";
20918
- AssetType[/** Cube Texture. */ "TextureCube"] = "TextureCube";
20919
- AssetType[/** Material. */ "Material"] = "Material";
20920
- AssetType[/** Mesh. */ "Mesh"] = "Mesh";
20921
- AssetType[/** AnimationClip. */ "AnimationClip"] = "AnimationClip";
20922
- AssetType[/** AnimatorController. */ "AnimatorController"] = "AnimatorController";
20923
- AssetType[/** Prefab.*/ "GLTF"] = "GLTF";
20924
- AssetType[/** Compress Texture. */ "KTX"] = "KTX";
20925
- AssetType[/** Cube Compress Texture. */ "KTXCube"] = "KTXCube";
20926
- AssetType[/** KTX2 Compress Texture */ "KTX2"] = "KTX2";
20927
- AssetType[/** Sprite. */ "Sprite"] = "Sprite";
20928
- AssetType[/** Sprite Atlas. */ "SpriteAtlas"] = "SpriteAtlas";
20929
- AssetType[/** Ambient light. */ "Env"] = "Environment";
20930
- AssetType[/** Scene. */ "Scene"] = "Scene";
20931
- AssetType[/** HDR to cube. */ "HDR"] = "HDR";
20932
- AssetType[/** Font. */ "Font"] = "Font";
20933
- AssetType[/** Source Font, include ttf、 otf and woff. */ "SourceFont"] = "SourceFont";
20934
- })(exports.AssetType || (exports.AssetType = {}));
20935
-
20936
21002
  /**
20937
21003
  * Alpha blend mode.
20938
21004
  */ exports.BlendMode = void 0;