@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.
package/dist/module.js CHANGED
@@ -2761,6 +2761,8 @@ var DependentMode;
2761
2761
  function DisorderedArray(count) {
2762
2762
  if (count === void 0) count = 0;
2763
2763
  this.length = 0;
2764
+ this._isLooping = false;
2765
+ this._blankCount = 0;
2764
2766
  this._elements = new Array(count);
2765
2767
  }
2766
2768
  var _proto = DisorderedArray.prototype;
@@ -2789,21 +2791,49 @@ var DependentMode;
2789
2791
  }
2790
2792
  return this._elements[index];
2791
2793
  };
2794
+ _proto.startLoop = function startLoop() {
2795
+ this._isLooping = true;
2796
+ };
2792
2797
  /**
2793
2798
  * Delete the element at the specified index.
2794
2799
  * @param index - The index of the element to be deleted
2795
2800
  * @returns The replaced item is used to reset its index
2796
2801
  */ _proto.deleteByIndex = function deleteByIndex(index) {
2797
2802
  var elements = this._elements;
2798
- var end = null;
2799
- var lastIndex = this.length - 1;
2800
- if (index !== lastIndex) {
2801
- end = elements[lastIndex];
2802
- elements[index] = end;
2803
+ var end;
2804
+ if (this._isLooping) {
2805
+ this._elements[index] = null;
2806
+ this._blankCount++;
2807
+ } else {
2808
+ var endIndex = this.length - 1;
2809
+ if (index !== endIndex) {
2810
+ end = elements[endIndex];
2811
+ elements[index] = end;
2812
+ }
2813
+ elements[endIndex] = null;
2814
+ this.length--;
2803
2815
  }
2804
- this.length--;
2805
2816
  return end;
2806
2817
  };
2818
+ _proto.endLoop = function endLoop() {
2819
+ this._isLooping = false;
2820
+ if (this._blankCount) {
2821
+ var elements = this._elements;
2822
+ for(var i = 0, j = 0, n = this.length; i < n; i++){
2823
+ var element = elements[i];
2824
+ if (element) {
2825
+ elements[j++] = element;
2826
+ }
2827
+ }
2828
+ this.length -= this._blankCount;
2829
+ this._blankCount = 0;
2830
+ }
2831
+ };
2832
+ _proto.endLoopAndClear = function endLoopAndClear() {
2833
+ this._isLooping = false;
2834
+ this.length = 0;
2835
+ this._blankCount = 0;
2836
+ };
2807
2837
  _proto.garbageCollection = function garbageCollection() {
2808
2838
  this._elements.length = this.length;
2809
2839
  };
@@ -4040,11 +4070,13 @@ var ComponentCloner = /*#__PURE__*/ function() {
4040
4070
  if (!this._isActiveInHierarchy) {
4041
4071
  child._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
4042
4072
  }
4043
- if (this._isActiveInScene) {
4044
- // cross scene should inActive first and then active
4045
- child._isActiveInScene && oldScene !== newScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
4046
- } else {
4047
- child._isActiveInScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
4073
+ if (child._isActiveInScene) {
4074
+ if (this._isActiveInScene) {
4075
+ // Cross scene should inActive first and then active
4076
+ oldScene !== newScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
4077
+ } else {
4078
+ inActiveChangeFlag |= ActiveChangeFlag.Scene;
4079
+ }
4048
4080
  }
4049
4081
  inActiveChangeFlag && child._processInActive(inActiveChangeFlag);
4050
4082
  if (child._scene !== newScene) {
@@ -5017,7 +5049,7 @@ var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission
5017
5049
 
5018
5050
  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
5019
5051
 
5020
- 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
5052
+ 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
5021
5053
 
5022
5054
  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
5023
5055
 
@@ -5057,7 +5089,7 @@ var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecula
5057
5089
 
5058
5090
  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
5059
5091
 
5060
- 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
5092
+ 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
5061
5093
 
5062
5094
  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
5063
5095
 
@@ -11552,19 +11584,20 @@ var PrimitiveType;
11552
11584
  /**
11553
11585
  * @internal
11554
11586
  */ _proto.update = function update() {
11555
- var skin = this._skin;
11556
- if (skin) {
11557
- var ibms = skin.inverseBindMatrices;
11558
- var worldToLocal = this._rootBone.getInvModelMatrix();
11559
- var _this = this, bones = _this._bones, jointMatrices = _this._jointMatrices;
11587
+ var _this = this, skin = _this._skin, bones = _this._bones;
11588
+ if (skin && bones) {
11560
11589
  // @todo: can optimize when share skin
11590
+ var jointMatrices = this._jointMatrices;
11591
+ var bindMatrices = skin.inverseBindMatrices;
11592
+ var _this__rootBone;
11593
+ var worldToLocal = ((_this__rootBone = this._rootBone) != null ? _this__rootBone : this.entity).getInvModelMatrix();
11561
11594
  for(var i = bones.length - 1; i >= 0; i--){
11562
11595
  var bone = bones[i];
11563
11596
  var offset = i * 16;
11564
11597
  if (bone) {
11565
- Utils._floatMatrixMultiply(bone.transform.worldMatrix, ibms[i].elements, 0, jointMatrices, offset);
11598
+ Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, jointMatrices, offset);
11566
11599
  } else {
11567
- jointMatrices.set(ibms[i].elements, offset);
11600
+ jointMatrices.set(bindMatrices[i].elements, offset);
11568
11601
  }
11569
11602
  Utils._floatMatrixMultiply(worldToLocal, jointMatrices, offset, jointMatrices, offset);
11570
11603
  }
@@ -12235,6 +12268,41 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
12235
12268
  return TextRenderData;
12236
12269
  }(RenderData);
12237
12270
 
12271
+ /**
12272
+ * Asset Type.
12273
+ */ var AssetType;
12274
+ (function(AssetType) {
12275
+ AssetType[/**
12276
+ * Plain text.
12277
+ * @remarks Will not be cached based on url in ResourceManager.
12278
+ */ "Text"] = "Text";
12279
+ AssetType[/**
12280
+ * JSON.
12281
+ * @remarks Will not be cached based on url in ResourceManager.
12282
+ */ "JSON"] = "JSON";
12283
+ AssetType[/**
12284
+ * ArrayBuffer.
12285
+ * @remarks Will not be cached based on url in ResourceManager.
12286
+ */ "Buffer"] = "Buffer";
12287
+ AssetType[/** 2D Texture. */ "Texture2D"] = "Texture2D";
12288
+ AssetType[/** Cube Texture. */ "TextureCube"] = "TextureCube";
12289
+ AssetType[/** Material. */ "Material"] = "Material";
12290
+ AssetType[/** Mesh. */ "Mesh"] = "Mesh";
12291
+ AssetType[/** AnimationClip. */ "AnimationClip"] = "AnimationClip";
12292
+ AssetType[/** AnimatorController. */ "AnimatorController"] = "AnimatorController";
12293
+ AssetType[/** Prefab.*/ "GLTF"] = "GLTF";
12294
+ AssetType[/** Compress Texture. */ "KTX"] = "KTX";
12295
+ AssetType[/** Cube Compress Texture. */ "KTXCube"] = "KTXCube";
12296
+ AssetType[/** KTX2 Compress Texture */ "KTX2"] = "KTX2";
12297
+ AssetType[/** Sprite. */ "Sprite"] = "Sprite";
12298
+ AssetType[/** Sprite Atlas. */ "SpriteAtlas"] = "SpriteAtlas";
12299
+ AssetType[/** Ambient light. */ "Env"] = "Environment";
12300
+ AssetType[/** Scene. */ "Scene"] = "Scene";
12301
+ AssetType[/** HDR to cube. */ "HDR"] = "HDR";
12302
+ AssetType[/** Font. */ "Font"] = "Font";
12303
+ AssetType[/** Source Font, include ttf、 otf and woff. */ "SourceFont"] = "SourceFont";
12304
+ })(AssetType || (AssetType = {}));
12305
+
12238
12306
  var SafeLoopArray = /*#__PURE__*/ function() {
12239
12307
  function SafeLoopArray() {
12240
12308
  this._array = [];
@@ -12347,10 +12415,13 @@ var SafeLoopArray = /*#__PURE__*/ function() {
12347
12415
  */ _proto.loadScene = function loadScene(url, destroyOldScene) {
12348
12416
  if (destroyOldScene === void 0) destroyOldScene = true;
12349
12417
  var _this = this;
12350
- var scenePromise = this.engine.resourceManager.load(url);
12418
+ var scenePromise = this.engine.resourceManager.load({
12419
+ url: url,
12420
+ type: AssetType.Scene
12421
+ });
12351
12422
  scenePromise.then(function(scene) {
12352
- var scenes = _this._scenes;
12353
12423
  if (destroyOldScene) {
12424
+ var scenes = _this._scenes.getArray();
12354
12425
  for(var i = 0, n = scenes.length; i < n; i++){
12355
12426
  scenes[i].destroy();
12356
12427
  }
@@ -12980,17 +13051,21 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
12980
13051
  if (this._currentEnteredEntity !== rayCastEntity) {
12981
13052
  if (this._currentEnteredEntity) {
12982
13053
  var scripts = this._currentEnteredEntity._scripts;
12983
- for(var i = scripts.length - 1; i >= 0; i--){
12984
- var script = scripts.get(i);
12985
- script._waitHandlingInValid || script.onPointerExit(this);
13054
+ scripts.startLoop();
13055
+ for(var i = 0; i < scripts.length; i++){
13056
+ var _scripts_get;
13057
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onPointerExit(this);
12986
13058
  }
13059
+ scripts.endLoop();
12987
13060
  }
12988
13061
  if (rayCastEntity) {
12989
13062
  var scripts1 = rayCastEntity._scripts;
12990
- for(var i1 = scripts1.length - 1; i1 >= 0; i1--){
12991
- var script1 = scripts1.get(i1);
12992
- script1._waitHandlingInValid || script1.onPointerEnter(this);
13063
+ scripts1.startLoop();
13064
+ for(var i1 = 0; i1 < scripts1.length; i1++){
13065
+ var _scripts_get1;
13066
+ (_scripts_get1 = scripts1.get(i1)) == null ? void 0 : _scripts_get1.onPointerEnter(this);
12993
13067
  }
13068
+ scripts1.endLoop();
12994
13069
  }
12995
13070
  this._currentEnteredEntity = rayCastEntity;
12996
13071
  }
@@ -13000,10 +13075,12 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
13000
13075
  */ _proto._firePointerDown = function _firePointerDown(rayCastEntity) {
13001
13076
  if (rayCastEntity) {
13002
13077
  var scripts = rayCastEntity._scripts;
13003
- for(var i = scripts.length - 1; i >= 0; i--){
13004
- var script = scripts.get(i);
13005
- script._waitHandlingInValid || script.onPointerDown(this);
13078
+ scripts.startLoop();
13079
+ for(var i = 0; i < scripts.length; i++){
13080
+ var _scripts_get;
13081
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onPointerDown(this);
13006
13082
  }
13083
+ scripts.endLoop();
13007
13084
  }
13008
13085
  this._currentPressedEntity = rayCastEntity;
13009
13086
  };
@@ -13012,10 +13089,12 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
13012
13089
  */ _proto._firePointerDrag = function _firePointerDrag() {
13013
13090
  if (this._currentPressedEntity) {
13014
13091
  var scripts = this._currentPressedEntity._scripts;
13015
- for(var i = scripts.length - 1; i >= 0; i--){
13016
- var script = scripts.get(i);
13017
- script._waitHandlingInValid || script.onPointerDrag(this);
13092
+ scripts.startLoop();
13093
+ for(var i = 0; i < scripts.length; i++){
13094
+ var _scripts_get;
13095
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onPointerDrag(this);
13018
13096
  }
13097
+ scripts.endLoop();
13019
13098
  }
13020
13099
  };
13021
13100
  /**
@@ -13025,13 +13104,15 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
13025
13104
  if (pressedEntity) {
13026
13105
  var sameTarget = pressedEntity === rayCastEntity;
13027
13106
  var scripts = pressedEntity._scripts;
13028
- for(var i = scripts.length - 1; i >= 0; i--){
13107
+ scripts.startLoop();
13108
+ for(var i = 0; i < scripts.length; i++){
13029
13109
  var script = scripts.get(i);
13030
- if (!script._waitHandlingInValid) {
13110
+ if (script) {
13031
13111
  sameTarget && script.onPointerClick(this);
13032
13112
  script.onPointerUp(this);
13033
13113
  }
13034
13114
  }
13115
+ scripts.endLoop();
13035
13116
  this._currentPressedEntity = null;
13036
13117
  }
13037
13118
  };
@@ -13635,114 +13716,138 @@ var Collision = function Collision() {
13635
13716
  var shape1 = physicalObjectsMap[obj1];
13636
13717
  var shape2 = physicalObjectsMap[obj2];
13637
13718
  var scripts = shape1.collider.entity._scripts;
13638
- for(var i = 0, len = scripts.length; i < len; i++){
13719
+ scripts.startLoop();
13720
+ for(var i = 0; i < scripts.length; i++){
13639
13721
  var script = scripts.get(i);
13640
- if (!script._waitHandlingInValid) {
13722
+ if (script) {
13641
13723
  var collision = PhysicsScene._collision;
13642
13724
  collision.shape = shape2;
13643
13725
  script.onCollisionEnter(collision);
13644
13726
  }
13645
13727
  }
13728
+ scripts.endLoop();
13646
13729
  scripts = shape2.collider.entity._scripts;
13647
- for(var i1 = 0, len1 = scripts.length; i1 < len1; i1++){
13730
+ scripts.startLoop();
13731
+ for(var i1 = 0; i1 < scripts.length; i1++){
13648
13732
  var script1 = scripts.get(i1);
13649
- if (!script1._waitHandlingInValid) {
13733
+ if (script1) {
13650
13734
  var collision1 = PhysicsScene._collision;
13651
13735
  collision1.shape = shape1;
13652
13736
  script1.onCollisionEnter(collision1);
13653
13737
  }
13654
13738
  }
13739
+ scripts.endLoop();
13655
13740
  };
13656
13741
  this._onContactExit = function(obj1, obj2) {
13657
13742
  var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
13658
13743
  var shape1 = physicalObjectsMap[obj1];
13659
13744
  var shape2 = physicalObjectsMap[obj2];
13660
13745
  var scripts = shape1.collider.entity._scripts;
13661
- for(var i = 0, len = scripts.length; i < len; i++){
13746
+ scripts.startLoop();
13747
+ for(var i = 0; i < scripts.length; i++){
13662
13748
  var script = scripts.get(i);
13663
- if (!script._waitHandlingInValid) {
13749
+ if (script) {
13664
13750
  var collision = PhysicsScene._collision;
13665
13751
  collision.shape = shape2;
13666
13752
  script.onCollisionExit(collision);
13667
13753
  }
13668
13754
  }
13755
+ scripts.endLoop();
13669
13756
  scripts = shape2.collider.entity._scripts;
13670
- for(var i1 = 0, len1 = scripts.length; i1 < len1; i1++){
13757
+ scripts.startLoop();
13758
+ for(var i1 = 0; i1 < scripts.length; i1++){
13671
13759
  var script1 = scripts.get(i1);
13672
- if (!script1._waitHandlingInValid) {
13760
+ if (script1) {
13673
13761
  var collision1 = PhysicsScene._collision;
13674
13762
  collision1.shape = shape1;
13675
13763
  script1.onCollisionExit(collision1);
13676
13764
  }
13677
13765
  }
13766
+ scripts.endLoop();
13678
13767
  };
13679
13768
  this._onContactStay = function(obj1, obj2) {
13680
13769
  var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
13681
13770
  var shape1 = physicalObjectsMap[obj1];
13682
13771
  var shape2 = physicalObjectsMap[obj2];
13683
13772
  var scripts = shape1.collider.entity._scripts;
13684
- for(var i = 0, len = scripts.length; i < len; i++){
13773
+ scripts.startLoop();
13774
+ for(var i = 0; i < scripts.length; i++){
13685
13775
  var script = scripts.get(i);
13686
- if (!script._waitHandlingInValid) {
13776
+ if (script) {
13687
13777
  var collision = PhysicsScene._collision;
13688
13778
  collision.shape = shape2;
13689
13779
  script.onCollisionStay(collision);
13690
13780
  }
13691
13781
  }
13782
+ scripts.endLoop();
13692
13783
  scripts = shape2.collider.entity._scripts;
13693
- for(var i1 = 0, len1 = scripts.length; i1 < len1; i1++){
13784
+ scripts.startLoop();
13785
+ for(var i1 = 0; i1 < scripts.length; i1++){
13694
13786
  var script1 = scripts.get(i1);
13695
- if (!script1._waitHandlingInValid) {
13787
+ if (script1) {
13696
13788
  var collision1 = PhysicsScene._collision;
13697
13789
  collision1.shape = shape1;
13698
13790
  script1.onCollisionStay(collision1);
13699
13791
  }
13700
13792
  }
13793
+ scripts.endLoop();
13701
13794
  };
13702
13795
  this._onTriggerEnter = function(obj1, obj2) {
13703
13796
  var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
13704
13797
  var shape1 = physicalObjectsMap[obj1];
13705
13798
  var shape2 = physicalObjectsMap[obj2];
13706
13799
  var scripts = shape1.collider.entity._scripts;
13707
- for(var i = 0, len = scripts.length; i < len; i++){
13708
- var script = scripts.get(i);
13709
- script._waitHandlingInValid || script.onTriggerEnter(shape2);
13800
+ scripts.startLoop();
13801
+ for(var i = 0; i < scripts.length; i++){
13802
+ var _scripts_get;
13803
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onTriggerEnter(shape2);
13710
13804
  }
13805
+ scripts.endLoop();
13711
13806
  scripts = shape2.collider.entity._scripts;
13712
- for(var i1 = 0, len1 = scripts.length; i1 < len1; i1++){
13713
- var script1 = scripts.get(i1);
13714
- script1._waitHandlingInValid || script1.onTriggerEnter(shape1);
13807
+ scripts.startLoop();
13808
+ for(var i1 = 0; i1 < scripts.length; i1++){
13809
+ var _scripts_get1;
13810
+ (_scripts_get1 = scripts.get(i1)) == null ? void 0 : _scripts_get1.onTriggerEnter(shape1);
13715
13811
  }
13812
+ scripts.endLoop();
13716
13813
  };
13717
13814
  this._onTriggerExit = function(obj1, obj2) {
13718
13815
  var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
13719
13816
  var shape1 = physicalObjectsMap[obj1];
13720
13817
  var shape2 = physicalObjectsMap[obj2];
13721
13818
  var scripts = shape1.collider.entity._scripts;
13722
- for(var i = 0, n = scripts.length; i < n; i++){
13723
- var script = scripts.get(i);
13724
- script._waitHandlingInValid || script.onTriggerExit(shape2);
13819
+ scripts.startLoop();
13820
+ for(var i = 0; i < scripts.length; i++){
13821
+ var _scripts_get;
13822
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onTriggerExit(shape2);
13725
13823
  }
13824
+ scripts.endLoop();
13726
13825
  scripts = shape2.collider.entity._scripts;
13727
- for(var i1 = 0, n1 = scripts.length; i1 < n1; i1++){
13728
- var script1 = scripts.get(i1);
13729
- script1._waitHandlingInValid || script1.onTriggerExit(shape1);
13826
+ scripts.startLoop();
13827
+ for(var i1 = 0; i1 < scripts.length; i1++){
13828
+ var _scripts_get1;
13829
+ (_scripts_get1 = scripts.get(i1)) == null ? void 0 : _scripts_get1.onTriggerExit(shape1);
13730
13830
  }
13831
+ scripts.endLoop();
13731
13832
  };
13732
13833
  this._onTriggerStay = function(obj1, obj2) {
13733
13834
  var physicalObjectsMap = _this._scene.engine._physicalObjectsMap;
13734
13835
  var shape1 = physicalObjectsMap[obj1];
13735
13836
  var shape2 = physicalObjectsMap[obj2];
13736
13837
  var scripts = shape1.collider.entity._scripts;
13737
- for(var i = 0, len = scripts.length; i < len; i++){
13738
- var script = scripts.get(i);
13739
- script._waitHandlingInValid || script.onTriggerStay(shape2);
13838
+ scripts.startLoop();
13839
+ for(var i = 0; i < scripts.length; i++){
13840
+ var _scripts_get;
13841
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onTriggerStay(shape2);
13740
13842
  }
13843
+ scripts.endLoop();
13741
13844
  scripts = shape2.collider.entity._scripts;
13742
- for(var i1 = 0, len1 = scripts.length; i1 < len1; i1++){
13743
- var script1 = scripts.get(i1);
13744
- script1._waitHandlingInValid || script1.onTriggerStay(shape1);
13845
+ scripts.startLoop();
13846
+ for(var i1 = 0; i1 < scripts.length; i1++){
13847
+ var _scripts_get1;
13848
+ (_scripts_get1 = scripts.get(i1)) == null ? void 0 : _scripts_get1.onTriggerStay(shape1);
13745
13849
  }
13850
+ scripts.endLoop();
13746
13851
  };
13747
13852
  this._scene = scene;
13748
13853
  this._setGravity = this._setGravity.bind(this);
@@ -16880,7 +16985,6 @@ ShaderPool.init();
16880
16985
  this._onUpdateScripts = new DisorderedArray();
16881
16986
  this._onLateUpdateScripts = new DisorderedArray();
16882
16987
  this._onPhysicsUpdateScripts = new DisorderedArray();
16883
- this._disableScripts = [];
16884
16988
  this._pendingDestroyScripts = [];
16885
16989
  this._disposeDestroyScripts = [];
16886
16990
  // Animation
@@ -16958,102 +17062,110 @@ ShaderPool.init();
16958
17062
  replaced && (replaced._onUpdateIndex = renderer._onUpdateIndex);
16959
17063
  renderer._onUpdateIndex = -1;
16960
17064
  };
16961
- _proto.addDisableScript = function addDisableScript(component) {
16962
- this._disableScripts.push(component);
16963
- };
16964
17065
  _proto.addPendingDestroyScript = function addPendingDestroyScript(component) {
16965
17066
  this._pendingDestroyScripts.push(component);
16966
17067
  };
16967
17068
  _proto.callScriptOnStart = function callScriptOnStart() {
16968
17069
  var onStartScripts = this._onStartScripts;
16969
17070
  if (onStartScripts.length > 0) {
17071
+ onStartScripts.startLoop();
16970
17072
  var elements = onStartScripts._elements;
16971
17073
  // The 'onStartScripts.length' maybe add if you add some Script with addComponent() in some Script's onStart()
16972
17074
  for(var i = 0; i < onStartScripts.length; i++){
16973
17075
  var script = elements[i];
16974
- if (!script._waitHandlingInValid) {
17076
+ if (script) {
16975
17077
  script._started = true;
16976
- script._onStartIndex = -1;
17078
+ this.removeOnStartScript(script);
16977
17079
  script.onStart();
16978
17080
  }
16979
17081
  }
16980
- onStartScripts.length = 0;
17082
+ onStartScripts.endLoopAndClear();
16981
17083
  }
16982
17084
  };
16983
17085
  _proto.callScriptOnUpdate = function callScriptOnUpdate(deltaTime) {
16984
- var elements = this._onUpdateScripts._elements;
16985
- for(var i = this._onUpdateScripts.length - 1; i >= 0; --i){
17086
+ var onUpdateScripts = this._onUpdateScripts;
17087
+ onUpdateScripts.startLoop();
17088
+ var elements = onUpdateScripts._elements;
17089
+ for(var i = 0; i < onUpdateScripts.length; i++){
16986
17090
  var element = elements[i];
16987
- if (!element._waitHandlingInValid && element._started) {
17091
+ if (element == null ? void 0 : element._started) {
16988
17092
  element.onUpdate(deltaTime);
16989
17093
  }
16990
17094
  }
17095
+ onUpdateScripts.endLoop();
16991
17096
  };
16992
17097
  _proto.callScriptOnLateUpdate = function callScriptOnLateUpdate(deltaTime) {
16993
- var elements = this._onLateUpdateScripts._elements;
16994
- for(var i = this._onLateUpdateScripts.length - 1; i >= 0; --i){
17098
+ var onLateUpdateScripts = this._onLateUpdateScripts;
17099
+ onLateUpdateScripts.startLoop();
17100
+ var elements = onLateUpdateScripts._elements;
17101
+ for(var i = 0; i < onLateUpdateScripts.length; i++){
16995
17102
  var element = elements[i];
16996
- if (!element._waitHandlingInValid && element._started) {
17103
+ if (element == null ? void 0 : element._started) {
16997
17104
  element.onLateUpdate(deltaTime);
16998
17105
  }
16999
17106
  }
17107
+ onLateUpdateScripts.endLoop();
17000
17108
  };
17001
17109
  _proto.callScriptOnPhysicsUpdate = function callScriptOnPhysicsUpdate() {
17002
- var elements = this._onPhysicsUpdateScripts._elements;
17003
- for(var i = this._onPhysicsUpdateScripts.length - 1; i >= 0; --i){
17110
+ var onPhysicsUpdateScripts = this._onPhysicsUpdateScripts;
17111
+ onPhysicsUpdateScripts.startLoop();
17112
+ var elements = onPhysicsUpdateScripts._elements;
17113
+ for(var i = 0; i < onPhysicsUpdateScripts.length; i++){
17004
17114
  var element = elements[i];
17005
- if (!element._waitHandlingInValid && element._started) {
17115
+ if (element == null ? void 0 : element._started) {
17006
17116
  element.onPhysicsUpdate();
17007
17117
  }
17008
17118
  }
17119
+ onPhysicsUpdateScripts.endLoop();
17009
17120
  };
17010
17121
  _proto.callAnimationUpdate = function callAnimationUpdate(deltaTime) {
17011
- var elements = this._onUpdateAnimations._elements;
17012
- for(var i = this._onUpdateAnimations.length - 1; i >= 0; --i){
17122
+ var onUpdateAnimations = this._onUpdateAnimations;
17123
+ onUpdateAnimations.startLoop();
17124
+ var elements = onUpdateAnimations._elements;
17125
+ for(var i = 0; i < onUpdateAnimations.length; i++){
17013
17126
  //@ts-ignore
17014
17127
  elements[i].update(deltaTime);
17015
17128
  }
17129
+ onUpdateAnimations.endLoop();
17016
17130
  };
17017
17131
  _proto.callRendererOnUpdate = function callRendererOnUpdate(deltaTime) {
17018
- var elements = this._onUpdateRenderers._elements;
17019
- for(var i = this._onUpdateRenderers.length - 1; i >= 0; --i){
17132
+ var onUpdateRenderers = this._onUpdateRenderers;
17133
+ onUpdateRenderers.startLoop();
17134
+ var elements = onUpdateRenderers._elements;
17135
+ for(var i = 0; i < onUpdateRenderers.length; i++){
17020
17136
  elements[i].update(deltaTime);
17021
17137
  }
17138
+ onUpdateRenderers.endLoop();
17022
17139
  };
17023
17140
  _proto.handlingInvalidScripts = function handlingInvalidScripts() {
17024
- var _this = this, disableScripts = _this._disableScripts;
17025
- var length = disableScripts.length;
17026
- if (length > 0) {
17027
- for(var i = length - 1; i >= 0; i--){
17028
- var disableScript = disableScripts[i];
17029
- disableScript._waitHandlingInValid && disableScript._handlingInValid();
17030
- }
17031
- disableScripts.length = 0;
17032
- }
17033
- var _this1 = this, pendingDestroyScripts = _this1._disposeDestroyScripts, disposeDestroyScripts = _this1._pendingDestroyScripts;
17141
+ var _this = this, pendingDestroyScripts = _this._disposeDestroyScripts, disposeDestroyScripts = _this._pendingDestroyScripts;
17034
17142
  this._disposeDestroyScripts = disposeDestroyScripts;
17035
17143
  this._pendingDestroyScripts = pendingDestroyScripts;
17036
17144
  length = disposeDestroyScripts.length;
17037
17145
  if (length > 0) {
17038
- for(var i1 = length - 1; i1 >= 0; i1--){
17039
- disposeDestroyScripts[i1].onDestroy();
17146
+ for(var i = length - 1; i >= 0; i--){
17147
+ disposeDestroyScripts[i].onDestroy();
17040
17148
  }
17041
17149
  disposeDestroyScripts.length = 0;
17042
17150
  }
17043
17151
  };
17044
17152
  _proto.callCameraOnBeginRender = function callCameraOnBeginRender(camera) {
17045
17153
  var scripts = camera.entity._scripts;
17046
- for(var i = scripts.length - 1; i >= 0; --i){
17047
- var script = scripts.get(i);
17048
- script._waitHandlingInValid || script.onBeginRender(camera);
17154
+ scripts.startLoop();
17155
+ for(var i = 0; i < scripts.length; i++){
17156
+ var _scripts_get;
17157
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onBeginRender(camera);
17049
17158
  }
17159
+ scripts.endLoop();
17050
17160
  };
17051
17161
  _proto.callCameraOnEndRender = function callCameraOnEndRender(camera) {
17052
17162
  var scripts = camera.entity._scripts;
17053
- for(var i = scripts.length - 1; i >= 0; --i){
17054
- var script = scripts.get(i);
17055
- script._waitHandlingInValid || script.onEndRender(camera);
17163
+ scripts.startLoop();
17164
+ for(var i = 0; i < scripts.length; i++){
17165
+ var _scripts_get;
17166
+ (_scripts_get = scripts.get(i)) == null ? void 0 : _scripts_get.onEndRender(camera);
17056
17167
  }
17168
+ scripts.endLoop();
17057
17169
  };
17058
17170
  _proto.getActiveChangedTempList = function getActiveChangedTempList() {
17059
17171
  return this._componentsContainerPool.length ? this._componentsContainerPool.pop() : [];
@@ -18024,19 +18136,20 @@ __decorate([
18024
18136
  }
18025
18137
  // Process entity active/inActive
18026
18138
  var inActiveChangeFlag = ActiveChangeFlag.None;
18027
- if (this._isActiveInEngine) {
18028
- // Cross scene should inActive first and then active
18029
- entity._isActiveInHierarchy && oldScene !== this && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
18030
- } else {
18031
- entity._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
18139
+ if (entity._isActiveInHierarchy) {
18140
+ this._isActiveInEngine || (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
18032
18141
  }
18142
+ // Cross scene should inActive first and then active
18143
+ entity._isActiveInScene && oldScene !== this && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
18033
18144
  inActiveChangeFlag && entity._processInActive(inActiveChangeFlag);
18034
18145
  if (oldScene !== this) {
18035
18146
  Entity._traverseSetOwnerScene(entity, this);
18036
18147
  }
18037
18148
  var activeChangeFlag = ActiveChangeFlag.None;
18038
- if (this._isActiveInEngine && entity._isActive) {
18039
- !entity._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
18149
+ if (entity._isActive) {
18150
+ if (this._isActiveInEngine) {
18151
+ !entity._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
18152
+ }
18040
18153
  (!entity._isActiveInScene || oldScene !== this) && (activeChangeFlag |= ActiveChangeFlag.Scene);
18041
18154
  }
18042
18155
  activeChangeFlag && entity._processActive(activeChangeFlag);
@@ -18392,7 +18505,6 @@ __decorate([
18392
18505
  /** @internal */ _this._onPreRenderIndex = -1;
18393
18506
  /** @internal */ _this._onPostRenderIndex = -1;
18394
18507
  _this._entityScriptsIndex = -1;
18395
- _this._waitHandlingInValid = false;
18396
18508
  return _this;
18397
18509
  }
18398
18510
  var _proto = Script.prototype;
@@ -18501,37 +18613,30 @@ __decorate([
18501
18613
  /**
18502
18614
  * @internal
18503
18615
  */ _proto._onEnableInScene = function _onEnableInScene() {
18504
- if (this._waitHandlingInValid) {
18505
- this._waitHandlingInValid = false;
18506
- } else {
18507
- var _this_scene = this.scene, componentsManager = _this_scene._componentsManager;
18508
- var prototype = Script.prototype;
18509
- if (!this._started) {
18510
- componentsManager.addOnStartScript(this);
18511
- }
18512
- if (this.onUpdate !== prototype.onUpdate) {
18513
- componentsManager.addOnUpdateScript(this);
18514
- }
18515
- if (this.onLateUpdate !== prototype.onLateUpdate) {
18516
- componentsManager.addOnLateUpdateScript(this);
18517
- }
18518
- if (this.onPhysicsUpdate !== prototype.onPhysicsUpdate) {
18519
- componentsManager.addOnPhysicsUpdateScript(this);
18520
- }
18521
- this._entity._addScript(this);
18616
+ var _this_scene = this.scene, componentsManager = _this_scene._componentsManager;
18617
+ var prototype = Script.prototype;
18618
+ if (!this._started) {
18619
+ componentsManager.addOnStartScript(this);
18620
+ }
18621
+ if (this.onUpdate !== prototype.onUpdate) {
18622
+ componentsManager.addOnUpdateScript(this);
18623
+ }
18624
+ if (this.onLateUpdate !== prototype.onLateUpdate) {
18625
+ componentsManager.addOnLateUpdateScript(this);
18626
+ }
18627
+ if (this.onPhysicsUpdate !== prototype.onPhysicsUpdate) {
18628
+ componentsManager.addOnPhysicsUpdateScript(this);
18522
18629
  }
18630
+ this._entity._addScript(this);
18523
18631
  };
18524
18632
  /**
18525
18633
  * @internal
18526
18634
  */ _proto._onDisableInScene = function _onDisableInScene() {
18527
- this._waitHandlingInValid = true;
18528
- this.scene._componentsManager.addDisableScript(this);
18529
- };
18530
- /**
18531
- * @internal
18532
- */ _proto._handlingInValid = function _handlingInValid() {
18533
18635
  var componentsManager = this.scene._componentsManager;
18534
18636
  var prototype = Script.prototype;
18637
+ if (!this._started) {
18638
+ componentsManager.removeOnStartScript(this);
18639
+ }
18535
18640
  if (this.onUpdate !== prototype.onUpdate) {
18536
18641
  componentsManager.removeOnUpdateScript(this);
18537
18642
  }
@@ -18542,7 +18647,6 @@ __decorate([
18542
18647
  componentsManager.removeOnPhysicsUpdateScript(this);
18543
18648
  }
18544
18649
  this._entity._removeScript(this);
18545
- this._waitHandlingInValid = false;
18546
18650
  };
18547
18651
  /**
18548
18652
  * @internal
@@ -18576,9 +18680,6 @@ __decorate([
18576
18680
  __decorate([
18577
18681
  ignoreClone
18578
18682
  ], Script.prototype, "_entityScriptsIndex", void 0);
18579
- __decorate([
18580
- ignoreClone
18581
- ], Script.prototype, "_waitHandlingInValid", void 0);
18582
18683
 
18583
18684
  /**
18584
18685
  * Depth texture mode.
@@ -20893,41 +20994,6 @@ var MultiExecutor = /*#__PURE__*/ function() {
20893
20994
  Loader._engineObjects = {};
20894
20995
  })();
20895
20996
 
20896
- /**
20897
- * Asset Type.
20898
- */ var AssetType;
20899
- (function(AssetType) {
20900
- AssetType[/**
20901
- * Plain text.
20902
- * @remarks Will not be cached based on url in ResourceManager.
20903
- */ "Text"] = "Text";
20904
- AssetType[/**
20905
- * JSON.
20906
- * @remarks Will not be cached based on url in ResourceManager.
20907
- */ "JSON"] = "JSON";
20908
- AssetType[/**
20909
- * ArrayBuffer.
20910
- * @remarks Will not be cached based on url in ResourceManager.
20911
- */ "Buffer"] = "Buffer";
20912
- AssetType[/** 2D Texture. */ "Texture2D"] = "Texture2D";
20913
- AssetType[/** Cube Texture. */ "TextureCube"] = "TextureCube";
20914
- AssetType[/** Material. */ "Material"] = "Material";
20915
- AssetType[/** Mesh. */ "Mesh"] = "Mesh";
20916
- AssetType[/** AnimationClip. */ "AnimationClip"] = "AnimationClip";
20917
- AssetType[/** AnimatorController. */ "AnimatorController"] = "AnimatorController";
20918
- AssetType[/** Prefab.*/ "GLTF"] = "GLTF";
20919
- AssetType[/** Compress Texture. */ "KTX"] = "KTX";
20920
- AssetType[/** Cube Compress Texture. */ "KTXCube"] = "KTXCube";
20921
- AssetType[/** KTX2 Compress Texture */ "KTX2"] = "KTX2";
20922
- AssetType[/** Sprite. */ "Sprite"] = "Sprite";
20923
- AssetType[/** Sprite Atlas. */ "SpriteAtlas"] = "SpriteAtlas";
20924
- AssetType[/** Ambient light. */ "Env"] = "Environment";
20925
- AssetType[/** Scene. */ "Scene"] = "Scene";
20926
- AssetType[/** HDR to cube. */ "HDR"] = "HDR";
20927
- AssetType[/** Font. */ "Font"] = "Font";
20928
- AssetType[/** Source Font, include ttf、 otf and woff. */ "SourceFont"] = "SourceFont";
20929
- })(AssetType || (AssetType = {}));
20930
-
20931
20997
  /**
20932
20998
  * Alpha blend mode.
20933
20999
  */ var BlendMode;