@galacean/engine-core 1.2.0-alpha.1 → 1.2.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
@@ -595,7 +595,14 @@ var Utils = /*#__PURE__*/ function() {
595
595
  * @param url - The url to be judged.
596
596
  * @returns Whether the url is absolute url.
597
597
  */ Utils.isAbsoluteUrl = function isAbsoluteUrl(url) {
598
- return /^(?:http|blob|data:|\/)/.test(url);
598
+ return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
599
+ };
600
+ /**
601
+ * Judge whether the url is base64 url.
602
+ * @param url - The url to be judged.
603
+ * @returns Whether the url is base64 url.
604
+ */ Utils.isBase64Url = function isBase64Url(url) {
605
+ return /^data:.*,.*$/i.test(url);
599
606
  };
600
607
  /**
601
608
  * Get the values of an object.
@@ -613,7 +620,10 @@ var Utils = /*#__PURE__*/ function() {
613
620
  if (Utils.isAbsoluteUrl(relativeUrl)) {
614
621
  return relativeUrl;
615
622
  }
616
- return baseUrl.substring(0, baseUrl.lastIndexOf("/") + 1) + this._formatRelativePath(relativeUrl);
623
+ if (Utils.isBase64Url(relativeUrl)) {
624
+ return relativeUrl;
625
+ }
626
+ return relativeUrl ? baseUrl.replace(/\/+$/, "") + "/" + relativeUrl.replace(/^\/+/, "") : baseUrl;
617
627
  };
618
628
  /**
619
629
  * @internal
@@ -3169,7 +3179,7 @@ function _extends() {
3169
3179
  return _extends.apply(this, arguments);
3170
3180
  }
3171
3181
 
3172
- var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;"; // eslint-disable-line
3182
+ var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;uniform vec3 camera_Forward;"; // eslint-disable-line
3173
3183
 
3174
3184
  var common = "#define GLSLIFY 1\n#define PI 3.14159265359\n#define RECIPROCAL_PI 0.31830988618\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate( a ) clamp( a, 0.0, 1.0 )\nfloat pow2(float x){return x*x;}vec4 RGBMToLinear(vec4 value,float maxRange){return vec4(value.rgb*value.a*maxRange,1.0);}vec4 gammaToLinear(vec4 srgbIn){return vec4(pow(srgbIn.rgb,vec3(2.2)),srgbIn.a);}vec4 linearToGamma(vec4 linearIn){return vec4(pow(linearIn.rgb,vec3(1.0/2.2)),linearIn.a);}uniform vec4 camera_DepthBufferParams;float remapDepthBufferLinear01(float z){return 1.0/(camera_DepthBufferParams.x*z+camera_DepthBufferParams.y);}\n#ifdef GRAPHICS_API_WEBGL2\n#define INVERSE_MAT(mat) inverse(mat)\n#else\nmat2 inverseMat(mat2 m){return mat2(m[1][1],-m[0][1],-m[1][0],m[0][0])/(m[0][0]*m[1][1]-m[0][1]*m[1][0]);}mat3 inverseMat(mat3 m){float a00=m[0][0],a01=m[0][1],a02=m[0][2];float a10=m[1][0],a11=m[1][1],a12=m[1][2];float a20=m[2][0],a21=m[2][1],a22=m[2][2];float b01=a22*a11-a12*a21;float b11=-a22*a10+a12*a20;float b21=a21*a10-a11*a20;float det=a00*b01+a01*b11+a02*b21;return mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),b11,(a22*a00-a02*a20),(-a12*a00+a02*a10),b21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;}mat4 inverseMat(mat4 m){float a00=m[0][0],a01=m[0][1],a02=m[0][2],a03=m[0][3],a10=m[1][0],a11=m[1][1],a12=m[1][2],a13=m[1][3],a20=m[2][0],a21=m[2][1],a22=m[2][2],a23=m[2][3],a30=m[3][0],a31=m[3][1],a32=m[3][2],a33=m[3][3],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return mat4(a11*b11-a12*b10+a13*b09,a02*b10-a01*b11-a03*b09,a31*b05-a32*b04+a33*b03,a22*b04-a21*b05-a23*b03,a12*b08-a10*b11-a13*b07,a00*b11-a02*b08+a03*b07,a32*b02-a30*b05-a33*b01,a20*b05-a22*b02+a23*b01,a10*b10-a11*b08+a13*b06,a01*b08-a00*b10-a03*b06,a30*b04-a31*b02+a33*b00,a21*b02-a20*b04-a23*b00,a11*b07-a10*b09-a12*b06,a00*b09-a01*b07+a02*b06,a31*b01-a30*b03-a32*b00,a20*b03-a21*b01+a22*b00)/det;}\n#define INVERSE_MAT(mat) inverseMat(mat)\n#endif\n"; // eslint-disable-line
3175
3185
 
@@ -3219,7 +3229,7 @@ var mobile_material_frag = "#define GLSLIFY 1\nuniform vec4 material_EmissiveCol
3219
3229
 
3220
3230
  var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission=material_EmissiveColor;vec4 diffuse=material_BaseColor;vec4 specular=material_SpecularColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nvec4 emissiveTextureColor=texture2D(material_EmissiveTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nemissiveTextureColor=gammaToLinear(emissiveTextureColor);\n#endif\nemission*=emissiveTextureColor;\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 diffuseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ndiffuseTextureColor=gammaToLinear(diffuseTextureColor);\n#endif\ndiffuse*=diffuseTextureColor;\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\ndiffuse*=v_color;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\nvec4 specularTextureColor=texture2D(material_SpecularTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularTextureColor=gammaToLinear(specularTextureColor);\n#endif\nspecular*=specularTextureColor;\n#endif\nambient=vec4(scene_EnvMapLight.diffuse*scene_EnvMapLight.diffuseIntensity,1.0)*diffuse;"; // eslint-disable-line
3221
3231
 
3222
- 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
3232
+ var begin_viewdir_frag = "#define GLSLIFY 1\n#ifdef CAMERA_ORTHOGRAPHIC\nvec3 V=-camera_Forward;\n#else\n#ifdef MATERIAL_NEED_WORLD_POS\nvec3 V=normalize(camera_Position-v_pos);\n#endif\n#endif\n"; // eslint-disable-line
3223
3233
 
3224
3234
  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
3225
3235
 
@@ -3257,7 +3267,7 @@ var noise_simplex_4D = "#define GLSLIFY 1\nvec4 grad4(float j,vec4 ip){const vec
3257
3267
 
3258
3268
  var pbr_frag_define = "#define GLSLIFY 1\n#define MIN_PERCEPTUAL_ROUGHNESS 0.045\n#define MIN_ROUGHNESS 0.002025\nuniform float material_AlphaCutoff;uniform vec4 material_BaseColor;uniform float material_Metal;uniform float material_Roughness;uniform float material_IOR;uniform vec3 material_PBRSpecularColor;uniform float material_Glossiness;uniform vec3 material_EmissiveColor;uniform float material_NormalIntensity;uniform float material_OcclusionIntensity;uniform float material_OcclusionTextureCoord;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nuniform float material_ClearCoat;uniform float material_ClearCoatRoughness;\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nuniform sampler2D material_ClearCoatTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nuniform sampler2D material_ClearCoatRoughnessTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\nuniform sampler2D material_ClearCoatNormalTexture;\n#endif\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nuniform vec3 material_AnisotropyInfo;\n#ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\nuniform sampler2D material_AnisotropyTexture;\n#endif\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nuniform sampler2D material_BaseTexture;\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nuniform sampler2D material_NormalTexture;\n#endif\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nuniform sampler2D material_EmissiveTexture;\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nuniform sampler2D material_RoughnessMetallicTexture;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nuniform sampler2D material_SpecularGlossinessTexture;\n#endif\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\nuniform sampler2D material_OcclusionTexture;\n#endif\nstruct ReflectedLight{vec3 directDiffuse;vec3 directSpecular;vec3 indirectDiffuse;vec3 indirectSpecular;};struct Geometry{vec3 position;vec3 normal;vec3 viewDir;float dotNV;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nvec3 clearCoatNormal;float clearCoatDotNV;\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 anisotropicT;vec3 anisotropicB;vec3 anisotropicN;float anisotropy;\n#endif\n};struct Material{vec3 diffuseColor;float roughness;vec3 specularColor;float opacity;float f0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoat;float clearCoatRoughness;\n#endif\n};"; // eslint-disable-line
3259
3269
 
3260
- var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecularOcclusion(float ambientOcclusion,float roughness,float dotNV){return saturate(pow(dotNV+ambientOcclusion,exp2(-16.0*roughness-1.0))-1.0+ambientOcclusion);}float getAARoughnessFactor(vec3 normal){\n#ifdef HAS_DERIVATIVES\nvec3 dxy=max(abs(dFdx(normal)),abs(dFdy(normal)));return MIN_PERCEPTUAL_ROUGHNESS+max(max(dxy.x,dxy.y),dxy.z);\n#else\nreturn MIN_PERCEPTUAL_ROUGHNESS;\n#endif\n}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 getAnisotropicBentNormal(Geometry geometry,vec3 n,float roughness){vec3 anisotropyDirection=geometry.anisotropy>=0.0 ? geometry.anisotropicB : geometry.anisotropicT;vec3 anisotropicTangent=cross(anisotropyDirection,geometry.viewDir);vec3 anisotropicNormal=cross(anisotropicTangent,anisotropyDirection);vec3 bentNormal=normalize(mix(n,anisotropicNormal,abs(geometry.anisotropy)*saturate(5.0*roughness)));return bentNormal;}\n#endif\nvoid initGeometry(out Geometry geometry,bool isFrontFacing){geometry.position=v_pos;geometry.viewDir=normalize(camera_Position-v_pos);\n#if defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY)\nmat3 tbn=getTBN(isFrontFacing);\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\ngeometry.normal=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.normal=getNormal(isFrontFacing);\n#endif\ngeometry.dotNV=saturate(dot(geometry.normal,geometry.viewDir));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\ngeometry.clearCoatNormal=getNormalByNormalTexture(tbn,material_ClearCoatNormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.clearCoatNormal=getNormal(isFrontFacing);\n#endif\ngeometry.clearCoatDotNV=saturate(dot(geometry.clearCoatNormal,geometry.viewDir));\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat anisotropy=material_AnisotropyInfo.z;vec3 anisotropicDirection=vec3(material_AnisotropyInfo.xy,0.0);\n#ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\nvec3 anisotropyTextureInfo=texture2D(material_AnisotropyTexture,v_uv).rgb;anisotropy*=anisotropyTextureInfo.b;anisotropicDirection.xy*=anisotropyTextureInfo.rg*2.0-1.0;\n#endif\ngeometry.anisotropy=anisotropy;geometry.anisotropicT=normalize(tbn*anisotropicDirection);geometry.anisotropicB=normalize(cross(geometry.normal,geometry.anisotropicT));\n#endif\n}void initMaterial(out Material material,inout Geometry geometry){vec4 baseColor=material_BaseColor;float metal=material_Metal;float roughness=material_Roughness;vec3 specularColor=material_PBRSpecularColor;float glossiness=material_Glossiness;float alphaCutoff=material_AlphaCutoff;float f0=pow2((material_IOR-1.0)/(material_IOR+1.0));material.f0=f0;\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 baseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nbaseTextureColor=gammaToLinear(baseTextureColor);\n#endif\nbaseColor*=baseTextureColor;\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nbaseColor*=v_color;\n#endif\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(baseColor.a<alphaCutoff){discard;}\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nvec4 metalRoughMapColor=texture2D(material_RoughnessMetallicTexture,v_uv);roughness*=metalRoughMapColor.g;metal*=metalRoughMapColor.b;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nvec4 specularGlossinessColor=texture2D(material_SpecularGlossinessTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularGlossinessColor=gammaToLinear(specularGlossinessColor);\n#endif\nspecularColor*=specularGlossinessColor.rgb;glossiness*=specularGlossinessColor.a;\n#endif\n#ifdef IS_METALLIC_WORKFLOW\nmaterial.diffuseColor=baseColor.rgb*(1.0-metal);material.specularColor=mix(vec3(f0),baseColor.rgb,metal);material.roughness=roughness;\n#else\nfloat specularStrength=max(max(specularColor.r,specularColor.g),specularColor.b);material.diffuseColor=baseColor.rgb*(1.0-specularStrength);material.specularColor=specularColor;material.roughness=1.0-glossiness;\n#endif\nmaterial.roughness=max(material.roughness,getAARoughnessFactor(geometry.normal));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nmaterial.clearCoat=material_ClearCoat;material.clearCoatRoughness=material_ClearCoatRoughness;\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nmaterial.clearCoat*=texture2D(material_ClearCoatTexture,v_uv).r;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nmaterial.clearCoatRoughness*=texture2D(material_ClearCoatRoughnessTexture,v_uv).g;\n#endif\nmaterial.clearCoat=saturate(material.clearCoat);material.clearCoatRoughness=max(material.clearCoatRoughness,getAARoughnessFactor(geometry.clearCoatNormal));\n#endif\n#ifdef MATERIAL_IS_TRANSPARENT\nmaterial.opacity=baseColor.a;\n#else\nmaterial.opacity=1.0;\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\ngeometry.anisotropicN=getAnisotropicBentNormal(geometry,geometry.normal,material.roughness);\n#endif\n}\n#include <brdf>\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n"; // eslint-disable-line
3270
+ var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecularOcclusion(float ambientOcclusion,float roughness,float dotNV){return saturate(pow(dotNV+ambientOcclusion,exp2(-16.0*roughness-1.0))-1.0+ambientOcclusion);}float getAARoughnessFactor(vec3 normal){\n#ifdef HAS_DERIVATIVES\nvec3 dxy=max(abs(dFdx(normal)),abs(dFdy(normal)));return MIN_PERCEPTUAL_ROUGHNESS+max(max(dxy.x,dxy.y),dxy.z);\n#else\nreturn MIN_PERCEPTUAL_ROUGHNESS;\n#endif\n}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 getAnisotropicBentNormal(Geometry geometry,vec3 n,float roughness){vec3 anisotropyDirection=geometry.anisotropy>=0.0 ? geometry.anisotropicB : geometry.anisotropicT;vec3 anisotropicTangent=cross(anisotropyDirection,geometry.viewDir);vec3 anisotropicNormal=cross(anisotropicTangent,anisotropyDirection);vec3 bentNormal=normalize(mix(n,anisotropicNormal,abs(geometry.anisotropy)*saturate(5.0*roughness)));return bentNormal;}\n#endif\nvoid initGeometry(out Geometry geometry,bool isFrontFacing){geometry.position=v_pos;\n#ifdef CAMERA_ORTHOGRAPHIC\ngeometry.viewDir=-camera_Forward;\n#else\ngeometry.viewDir=normalize(camera_Position-v_pos);\n#endif\n#if defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY)\nmat3 tbn=getTBN(isFrontFacing);\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\ngeometry.normal=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.normal=getNormal(isFrontFacing);\n#endif\ngeometry.dotNV=saturate(dot(geometry.normal,geometry.viewDir));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\ngeometry.clearCoatNormal=getNormalByNormalTexture(tbn,material_ClearCoatNormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.clearCoatNormal=getNormal(isFrontFacing);\n#endif\ngeometry.clearCoatDotNV=saturate(dot(geometry.clearCoatNormal,geometry.viewDir));\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat anisotropy=material_AnisotropyInfo.z;vec3 anisotropicDirection=vec3(material_AnisotropyInfo.xy,0.0);\n#ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\nvec3 anisotropyTextureInfo=texture2D(material_AnisotropyTexture,v_uv).rgb;anisotropy*=anisotropyTextureInfo.b;anisotropicDirection.xy*=anisotropyTextureInfo.rg*2.0-1.0;\n#endif\ngeometry.anisotropy=anisotropy;geometry.anisotropicT=normalize(tbn*anisotropicDirection);geometry.anisotropicB=normalize(cross(geometry.normal,geometry.anisotropicT));\n#endif\n}void initMaterial(out Material material,inout Geometry geometry){vec4 baseColor=material_BaseColor;float metal=material_Metal;float roughness=material_Roughness;vec3 specularColor=material_PBRSpecularColor;float glossiness=material_Glossiness;float alphaCutoff=material_AlphaCutoff;float f0=pow2((material_IOR-1.0)/(material_IOR+1.0));material.f0=f0;\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 baseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nbaseTextureColor=gammaToLinear(baseTextureColor);\n#endif\nbaseColor*=baseTextureColor;\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nbaseColor*=v_color;\n#endif\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(baseColor.a<alphaCutoff){discard;}\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nvec4 metalRoughMapColor=texture2D(material_RoughnessMetallicTexture,v_uv);roughness*=metalRoughMapColor.g;metal*=metalRoughMapColor.b;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nvec4 specularGlossinessColor=texture2D(material_SpecularGlossinessTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularGlossinessColor=gammaToLinear(specularGlossinessColor);\n#endif\nspecularColor*=specularGlossinessColor.rgb;glossiness*=specularGlossinessColor.a;\n#endif\n#ifdef IS_METALLIC_WORKFLOW\nmaterial.diffuseColor=baseColor.rgb*(1.0-metal);material.specularColor=mix(vec3(f0),baseColor.rgb,metal);material.roughness=roughness;\n#else\nfloat specularStrength=max(max(specularColor.r,specularColor.g),specularColor.b);material.diffuseColor=baseColor.rgb*(1.0-specularStrength);material.specularColor=specularColor;material.roughness=1.0-glossiness;\n#endif\nmaterial.roughness=max(material.roughness,getAARoughnessFactor(geometry.normal));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nmaterial.clearCoat=material_ClearCoat;material.clearCoatRoughness=material_ClearCoatRoughness;\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nmaterial.clearCoat*=texture2D(material_ClearCoatTexture,v_uv).r;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nmaterial.clearCoatRoughness*=texture2D(material_ClearCoatRoughnessTexture,v_uv).g;\n#endif\nmaterial.clearCoat=saturate(material.clearCoat);material.clearCoatRoughness=max(material.clearCoatRoughness,getAARoughnessFactor(geometry.clearCoatNormal));\n#endif\n#ifdef MATERIAL_IS_TRANSPARENT\nmaterial.opacity=baseColor.a;\n#else\nmaterial.opacity=1.0;\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\ngeometry.anisotropicN=getAnisotropicBentNormal(geometry,geometry.normal,material.roughness);\n#endif\n}\n#include <brdf>\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n"; // eslint-disable-line
3261
3271
 
3262
3272
  var brdf = "#define GLSLIFY 1\nfloat F_Schlick(float f0,float dotLH){return f0+0.96*(pow(1.0-dotLH,5.0));}vec3 F_Schlick(vec3 specularColor,float dotLH){float fresnel=exp2((-5.55473*dotLH-6.98316)*dotLH);return(1.0-specularColor)*fresnel+specularColor;}float G_GGX_SmithCorrelated(float alpha,float dotNL,float dotNV){float a2=pow2(alpha);float gv=dotNL*sqrt(a2+(1.0-a2)*pow2(dotNV));float gl=dotNV*sqrt(a2+(1.0-a2)*pow2(dotNL));return 0.5/max(gv+gl,EPSILON);}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat G_GGX_SmithCorrelated_Anisotropic(float at,float ab,float ToV,float BoV,float ToL,float BoL,float NoV,float NoL){float lambdaV=NoL*length(vec3(at*ToV,ab*BoV,NoV));float lambdaL=NoV*length(vec3(at*ToL,ab*BoL,NoL));return 0.5/max(lambdaV+lambdaL,EPSILON);}\n#endif\nfloat D_GGX(float alpha,float dotNH){float a2=pow2(alpha);float denom=pow2(dotNH)*(a2-1.0)+1.0;return RECIPROCAL_PI*a2/pow2(denom);}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat D_GGX_Anisotropic(float at,float ab,float ToH,float BoH,float NoH){float a2=at*ab;highp vec3 d=vec3(ab*ToH,at*BoH,a2*NoH);highp float d2=dot(d,d);float b2=a2/d2;return a2*b2*b2*RECIPROCAL_PI;}\n#endif\nvec3 isotropicLobe(vec3 specularColor,float alpha,float dotNV,float dotNL,float dotNH,float dotLH){vec3 F=F_Schlick(specularColor,dotLH);float D=D_GGX(alpha,dotNH);float G=G_GGX_SmithCorrelated(alpha,dotNL,dotNV);return F*(G*D);}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 anisotropicLobe(vec3 h,vec3 l,Geometry geometry,vec3 specularColor,float alpha,float dotNV,float dotNL,float dotNH,float dotLH){vec3 t=geometry.anisotropicT;vec3 b=geometry.anisotropicB;vec3 v=geometry.viewDir;float dotTV=dot(t,v);float dotBV=dot(b,v);float dotTL=dot(t,l);float dotBL=dot(b,l);float dotTH=dot(t,h);float dotBH=dot(b,h);float at=max(alpha*(1.0+geometry.anisotropy),MIN_ROUGHNESS);float ab=max(alpha*(1.0-geometry.anisotropy),MIN_ROUGHNESS);vec3 F=F_Schlick(specularColor,dotLH);float D=D_GGX_Anisotropic(at,ab,dotTH,dotBH,dotNH);float G=G_GGX_SmithCorrelated_Anisotropic(at,ab,dotTV,dotBV,dotTL,dotBL,dotNV,dotNL);return F*(G*D);}\n#endif\nvec3 BRDF_Specular_GGX(vec3 incidentDirection,Geometry geometry,vec3 normal,vec3 specularColor,float roughness){float alpha=pow2(roughness);vec3 halfDir=normalize(incidentDirection+geometry.viewDir);float dotNL=saturate(dot(normal,incidentDirection));float dotNV=saturate(dot(normal,geometry.viewDir));float dotNH=saturate(dot(normal,halfDir));float dotLH=saturate(dot(incidentDirection,halfDir));\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nreturn anisotropicLobe(halfDir,incidentDirection,geometry,specularColor,alpha,dotNV,dotNL,dotNH,dotLH);\n#else\nreturn isotropicLobe(specularColor,alpha,dotNV,dotNL,dotNH,dotLH);\n#endif\n}vec3 BRDF_Diffuse_Lambert(vec3 diffuseColor){return RECIPROCAL_PI*diffuseColor;}"; // eslint-disable-line
3263
3273
 
@@ -3393,7 +3403,11 @@ var ShaderFactory = /*#__PURE__*/ function() {
3393
3403
  }
3394
3404
  ShaderLib[includeName] = includeSource;
3395
3405
  };
3396
- ShaderFactory.parseIncludes = function parseIncludes(src) {
3406
+ /**
3407
+ * @param regex The default regex is for engine's builtin glsl `#include` syntax,
3408
+ * since `ShaderLab` use the same parsing function but different syntax for `#include` --- `/^[ \t]*#include +"([\w\d.]+)"/gm`
3409
+ */ ShaderFactory.parseIncludes = function parseIncludes(src, regex) {
3410
+ if (regex === void 0) regex = /^[ \t]*#include +<([\w\d.]+)>/gm;
3397
3411
  var replace = function replace(match, slice) {
3398
3412
  var replace = ShaderLib[slice];
3399
3413
  if (replace === undefined) {
@@ -3402,7 +3416,6 @@ var ShaderFactory = /*#__PURE__*/ function() {
3402
3416
  }
3403
3417
  return ShaderFactory.parseIncludes(replace);
3404
3418
  };
3405
- var regex = /^[ \t]*#include +<([\w\d.]+)>/gm;
3406
3419
  return src.replace(regex, replace);
3407
3420
  };
3408
3421
  /**
@@ -6384,7 +6397,7 @@ SlicedSpriteAssembler = __decorate([
6384
6397
  _this._byteLength = byteLength;
6385
6398
  _this._platformBuffer = engine._hardwareRenderer.createPlatformBuffer(type, byteLength, bufferUsage, data);
6386
6399
  if (readable) {
6387
- var buffer = (data.constructor === ArrayBuffer ? data : data.buffer).slice(0, byteLength);
6400
+ var buffer = data.constructor === ArrayBuffer ? data.slice(0) : data.buffer.slice(data.byteOffset, data.byteOffset + byteLength);
6388
6401
  _this._data = new Uint8Array(buffer);
6389
6402
  }
6390
6403
  }
@@ -12879,6 +12892,9 @@ var /**
12879
12892
  var baseline = Math.ceil(context.measureText(TextUtils._measureBaseline).width);
12880
12893
  var height = baseline * TextUtils._heightMultiplier;
12881
12894
  baseline = TextUtils._baselineMultiplier * baseline | 0;
12895
+ var _extendHeight = TextUtils._extendHeight;
12896
+ height += _extendHeight;
12897
+ baseline += _extendHeight * 0.5;
12882
12898
  canvas.width = width;
12883
12899
  canvas.height = height;
12884
12900
  context.font = fontString;
@@ -12913,6 +12929,7 @@ var /**
12913
12929
  }
12914
12930
  if (top !== -1 && bottom !== -1) {
12915
12931
  ascent = baseline - top;
12932
+ // Baseline belong to descent
12916
12933
  descent = bottom - baseline + 1;
12917
12934
  size = ascent + descent;
12918
12935
  }
@@ -12989,9 +13006,8 @@ var /**
12989
13006
  ];
12990
13007
  })();
12991
13008
  (function() {
12992
- // _heightMultiplier used to measure the height of text, but in miniprogram performance is different from h5.
12993
- // so can set _heightMultiplier to adapt miniprogram, the larger the value, the worse the performance.
12994
- /** @internal */ TextUtils._heightMultiplier = 2;
13009
+ // _extendHeight used to extend the height of canvas, because in miniprogram performance is different from h5.
13010
+ /** @internal */ TextUtils._extendHeight = 0;
12995
13011
  })();
12996
13012
  (function() {
12997
13013
  /** These characters are all tall to help calculate the height required for text. */ TextUtils._measureString = "|\xc9q\xc5";
@@ -12999,6 +13015,9 @@ var /**
12999
13015
  (function() {
13000
13016
  TextUtils._measureBaseline = "M";
13001
13017
  })();
13018
+ (function() {
13019
+ TextUtils._heightMultiplier = 2;
13020
+ })();
13002
13021
  (function() {
13003
13022
  TextUtils._baselineMultiplier = 1.4;
13004
13023
  })();
@@ -14757,6 +14776,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData1) {
14757
14776
  AssetType[/** Cube Compress Texture. */ "KTXCube"] = "KTXCube";
14758
14777
  AssetType[/** KTX2 Compress Texture */ "KTX2"] = "KTX2";
14759
14778
  AssetType[/** Sprite. */ "Sprite"] = "Sprite";
14779
+ AssetType[/** PrimitiveMesh. */ "PrimitiveMesh"] = "PrimitiveMesh";
14760
14780
  AssetType[/** Sprite Atlas. */ "SpriteAtlas"] = "SpriteAtlas";
14761
14781
  AssetType[/** Ambient light. */ "Env"] = "Environment";
14762
14782
  AssetType[/** Scene. */ "Scene"] = "Scene";
@@ -15142,6 +15162,7 @@ var /** @internal */ PromiseState;
15142
15162
  this./** The number of retries after failing to load assets. */ retryCount = 1;
15143
15163
  this./** Retry delay time after failed to load assets, in milliseconds. */ retryInterval = 0;
15144
15164
  this./** The default timeout period for loading assets, in milliseconds. */ timeout = Infinity;
15165
+ this./** Base url for loading assets. */ baseUrl = null;
15145
15166
  this._loadingPromises = {};
15146
15167
  this._assetPool = Object.create(null);
15147
15168
  this._assetUrlPool = Object.create(null);
@@ -15345,6 +15366,8 @@ var /** @internal */ PromiseState;
15345
15366
  // Check url mapping
15346
15367
  var itemURL = item.url;
15347
15368
  var url = this._virtualPathMap[itemURL] ? this._virtualPathMap[itemURL] : itemURL;
15369
+ // Not absolute and base url is set
15370
+ if (!Utils.isAbsoluteUrl(url) && this.baseUrl) url = Utils.resolveAbsoluteUrl(this.baseUrl, url);
15348
15371
  // Parse url
15349
15372
  var _this__parseURL = this._parseURL(url), assetBaseURL = _this__parseURL.assetBaseURL, queryPath = _this__parseURL.queryPath;
15350
15373
  var paths = queryPath ? this._parseQueryPath(queryPath) : [];
@@ -16035,7 +16058,7 @@ SystemInfo._initialize();
16035
16058
  * Keyboard Manager.
16036
16059
  * @internal
16037
16060
  */ var KeyboardManager = /*#__PURE__*/ function() {
16038
- function KeyboardManager(engine) {
16061
+ function KeyboardManager(engine, target) {
16039
16062
  /** @internal */ this._curHeldDownKeyToIndexMap = [];
16040
16063
  /** @internal */ this._upKeyToFrameCountMap = [];
16041
16064
  /** @internal */ this._downKeyToFrameCountMap = [];
@@ -16043,17 +16066,11 @@ SystemInfo._initialize();
16043
16066
  /** @internal */ this._curFrameDownList = new DisorderedArray();
16044
16067
  /** @internal */ this._curFrameUpList = new DisorderedArray();
16045
16068
  this._nativeEvents = [];
16046
- this._hadListener = false;
16047
- // @ts-ignore
16048
- var htmlCanvas = engine._canvas._webCanvas;
16049
16069
  this._engine = engine;
16050
- this._htmlCanvas = htmlCanvas;
16051
- // Need to set tabIndex to make the canvas focus.
16052
- htmlCanvas.tabIndex = htmlCanvas.tabIndex;
16070
+ this._onBlur = this._onBlur.bind(this);
16053
16071
  this._onKeyEvent = this._onKeyEvent.bind(this);
16054
- htmlCanvas.addEventListener("keydown", this._onKeyEvent);
16055
- htmlCanvas.addEventListener("keyup", this._onKeyEvent);
16056
- this._hadListener = true;
16072
+ this._target = target;
16073
+ this._addEventListener();
16057
16074
  }
16058
16075
  var _proto = KeyboardManager.prototype;
16059
16076
  /**
@@ -16105,35 +16122,8 @@ SystemInfo._initialize();
16105
16122
  };
16106
16123
  /**
16107
16124
  * @internal
16108
- */ _proto._onFocus = function _onFocus() {
16109
- if (!this._hadListener) {
16110
- this._htmlCanvas.addEventListener("keydown", this._onKeyEvent);
16111
- this._htmlCanvas.addEventListener("keyup", this._onKeyEvent);
16112
- this._hadListener = true;
16113
- }
16114
- };
16115
- /**
16116
- * @internal
16117
- */ _proto._onBlur = function _onBlur() {
16118
- if (this._hadListener) {
16119
- this._htmlCanvas.removeEventListener("keydown", this._onKeyEvent);
16120
- this._htmlCanvas.removeEventListener("keyup", this._onKeyEvent);
16121
- this._curHeldDownKeyToIndexMap.length = 0;
16122
- this._curFrameHeldDownList.length = 0;
16123
- this._curFrameDownList.length = 0;
16124
- this._curFrameUpList.length = 0;
16125
- this._nativeEvents.length = 0;
16126
- this._hadListener = false;
16127
- }
16128
- };
16129
- /**
16130
- * @internal
16131
16125
  */ _proto._destroy = function _destroy() {
16132
- if (this._hadListener) {
16133
- this._htmlCanvas.removeEventListener("keydown", this._onKeyEvent);
16134
- this._htmlCanvas.removeEventListener("keyup", this._onKeyEvent);
16135
- this._hadListener = false;
16136
- }
16126
+ this._removeEventListener();
16137
16127
  this._curHeldDownKeyToIndexMap.length = 0;
16138
16128
  this._curHeldDownKeyToIndexMap = null;
16139
16129
  this._upKeyToFrameCountMap.length = 0;
@@ -16148,12 +16138,30 @@ SystemInfo._initialize();
16148
16138
  this._curFrameDownList = null;
16149
16139
  this._curFrameUpList.length = 0;
16150
16140
  this._curFrameUpList = null;
16151
- this._htmlCanvas = null;
16152
16141
  this._engine = null;
16153
16142
  };
16143
+ _proto._onBlur = function _onBlur() {
16144
+ this._curHeldDownKeyToIndexMap.length = 0;
16145
+ this._curFrameHeldDownList.length = 0;
16146
+ this._curFrameDownList.length = 0;
16147
+ this._curFrameUpList.length = 0;
16148
+ this._nativeEvents.length = 0;
16149
+ };
16154
16150
  _proto._onKeyEvent = function _onKeyEvent(evt) {
16155
16151
  this._nativeEvents.push(evt);
16156
16152
  };
16153
+ _proto._addEventListener = function _addEventListener() {
16154
+ var _this = this, target = _this._target;
16155
+ target.addEventListener("keydown", this._onKeyEvent);
16156
+ target.addEventListener("keyup", this._onKeyEvent);
16157
+ target.addEventListener("blur", this._onBlur);
16158
+ };
16159
+ _proto._removeEventListener = function _removeEventListener() {
16160
+ var _this = this, target = _this._target;
16161
+ target.removeEventListener("keydown", this._onKeyEvent);
16162
+ target.removeEventListener("keyup", this._onKeyEvent);
16163
+ target.removeEventListener("blur", this._onBlur);
16164
+ };
16157
16165
  return KeyboardManager;
16158
16166
  }();
16159
16167
 
@@ -18117,7 +18125,7 @@ __decorate([
18117
18125
  * Pointer Manager.
18118
18126
  * @internal
18119
18127
  */ var PointerManager = /*#__PURE__*/ function() {
18120
- function PointerManager(engine) {
18128
+ function PointerManager(engine, target) {
18121
18129
  /** @internal */ this._pointers = [];
18122
18130
  /** @internal */ this._multiPointerEnabled = true;
18123
18131
  /** @internal */ this._buttons = PointerButton.None;
@@ -18126,16 +18134,18 @@ __decorate([
18126
18134
  /** @internal */ this._upList = new DisorderedArray();
18127
18135
  /** @internal */ this._downList = new DisorderedArray();
18128
18136
  this._nativeEvents = [];
18129
- this._hadListener = false;
18130
- // @ts-ignore
18131
- var htmlCanvas = engine._canvas._webCanvas;
18137
+ if (_instanceof(target, Window)) {
18138
+ throw "Do not set window as target because window cannot listen to pointer leave event.";
18139
+ }
18132
18140
  this._engine = engine;
18141
+ this._target = target;
18133
18142
  this._canvas = engine.canvas;
18134
- this._htmlCanvas = htmlCanvas;
18135
- this._onPointerEvent = this._onPointerEvent.bind(this);
18136
- this._onFocus();
18143
+ // @ts-ignore
18144
+ this._htmlCanvas = engine._canvas._webCanvas;
18137
18145
  // If there are no compatibility issues, navigator.maxTouchPoints should be used here
18138
18146
  this._pointerPool = new Array(11);
18147
+ this._onPointerEvent = this._onPointerEvent.bind(this);
18148
+ this._addEventListener();
18139
18149
  }
18140
18150
  var _proto = PointerManager.prototype;
18141
18151
  /**
@@ -18205,7 +18215,8 @@ __decorate([
18205
18215
  var length = events.length;
18206
18216
  if (length > 0) {
18207
18217
  for(var i1 = 0; i1 < length; i1++){
18208
- switch(events[i1].type){
18218
+ var event = events[i1];
18219
+ switch(event.type){
18209
18220
  case "pointerdown":
18210
18221
  pointer.phase = PointerPhase.Down;
18211
18222
  pointer._firePointerDown(rayCastEntity);
@@ -18227,66 +18238,14 @@ __decorate([
18227
18238
  };
18228
18239
  /**
18229
18240
  * @internal
18230
- */ _proto._onFocus = function _onFocus() {
18231
- if (!this._hadListener) {
18232
- var _this = this, htmlCanvas = _this._htmlCanvas, onPointerEvent = _this._onPointerEvent;
18233
- htmlCanvas.addEventListener("pointerdown", onPointerEvent);
18234
- htmlCanvas.addEventListener("pointerup", onPointerEvent);
18235
- htmlCanvas.addEventListener("pointerleave", onPointerEvent);
18236
- htmlCanvas.addEventListener("pointermove", onPointerEvent);
18237
- htmlCanvas.addEventListener("pointercancel", onPointerEvent);
18238
- this._hadListener = true;
18239
- }
18240
- };
18241
- /**
18242
- * @internal
18243
- */ _proto._onBlur = function _onBlur() {
18244
- if (this._hadListener) {
18245
- var _this = this, htmlCanvas = _this._htmlCanvas, onPointerEvent = _this._onPointerEvent;
18246
- htmlCanvas.removeEventListener("pointerdown", onPointerEvent);
18247
- htmlCanvas.removeEventListener("pointerup", onPointerEvent);
18248
- htmlCanvas.removeEventListener("pointerleave", onPointerEvent);
18249
- htmlCanvas.removeEventListener("pointermove", onPointerEvent);
18250
- htmlCanvas.removeEventListener("pointercancel", onPointerEvent);
18251
- this._hadListener = false;
18252
- this._pointers.length = 0;
18253
- this._downList.length = 0;
18254
- this._upList.length = 0;
18255
- }
18256
- };
18257
- /**
18258
- * @internal
18259
18241
  */ _proto._destroy = function _destroy() {
18260
- // @ts-ignore
18261
- if (this._hadListener) {
18262
- var _this = this, htmlCanvas = _this._htmlCanvas, onPointerEvent = _this._onPointerEvent;
18263
- htmlCanvas.removeEventListener("pointerdown", onPointerEvent);
18264
- htmlCanvas.removeEventListener("pointerup", onPointerEvent);
18265
- htmlCanvas.removeEventListener("pointerleave", onPointerEvent);
18266
- htmlCanvas.removeEventListener("pointermove", onPointerEvent);
18267
- htmlCanvas.removeEventListener("pointercancel", onPointerEvent);
18268
- this._hadListener = false;
18269
- }
18242
+ this._removeEventListener();
18270
18243
  this._pointerPool.length = 0;
18271
- this._pointerPool = null;
18272
- this._pointers.length = 0;
18273
- this._pointers = null;
18274
- this._downList.length = 0;
18275
- this._downList = null;
18276
- this._upList.length = 0;
18277
- this._upList = null;
18278
18244
  this._nativeEvents.length = 0;
18279
- this._nativeEvents = null;
18280
- this._upMap.length = 0;
18281
- this._upMap = null;
18282
18245
  this._downMap.length = 0;
18283
- this._downMap = null;
18284
- this._htmlCanvas = null;
18285
- this._canvas = null;
18286
- this._engine = null;
18246
+ this._upMap.length = 0;
18287
18247
  };
18288
18248
  _proto._onPointerEvent = function _onPointerEvent(evt) {
18289
- evt.type === "pointerdown" && this._htmlCanvas.focus();
18290
18249
  this._nativeEvents.push(evt);
18291
18250
  };
18292
18251
  _proto._getPointerByID = function _getPointerByID(pointerId) {
@@ -18369,6 +18328,26 @@ __decorate([
18369
18328
  }
18370
18329
  return null;
18371
18330
  };
18331
+ _proto._addEventListener = function _addEventListener() {
18332
+ var _this = this, target = _this._target, onPointerEvent = _this._onPointerEvent;
18333
+ target.addEventListener("pointerdown", onPointerEvent);
18334
+ target.addEventListener("pointerup", onPointerEvent);
18335
+ target.addEventListener("pointerleave", onPointerEvent);
18336
+ target.addEventListener("pointermove", onPointerEvent);
18337
+ target.addEventListener("pointercancel", onPointerEvent);
18338
+ };
18339
+ _proto._removeEventListener = function _removeEventListener() {
18340
+ var _this = this, target = _this._target, onPointerEvent = _this._onPointerEvent;
18341
+ target.removeEventListener("pointerdown", onPointerEvent);
18342
+ target.removeEventListener("pointerup", onPointerEvent);
18343
+ target.removeEventListener("pointerleave", onPointerEvent);
18344
+ target.removeEventListener("pointermove", onPointerEvent);
18345
+ target.removeEventListener("pointercancel", onPointerEvent);
18346
+ this._nativeEvents.length = 0;
18347
+ this._pointers.length = 0;
18348
+ this._downList.length = 0;
18349
+ this._upList.length = 0;
18350
+ };
18372
18351
  return PointerManager;
18373
18352
  }();
18374
18353
  (function() {
@@ -18385,15 +18364,12 @@ __decorate([
18385
18364
  * Wheel Manager.
18386
18365
  * @internal
18387
18366
  */ var WheelManager = /*#__PURE__*/ function() {
18388
- function WheelManager(engine) {
18367
+ function WheelManager(engine, target) {
18389
18368
  /** @internal */ this._delta = new Vector3();
18390
18369
  this._nativeEvents = [];
18391
- // @ts-ignore
18392
- var htmlCanvas = engine._canvas._webCanvas;
18393
18370
  this._onWheelEvent = this._onWheelEvent.bind(this);
18394
- htmlCanvas.addEventListener("wheel", this._onWheelEvent);
18395
- this._canvas = htmlCanvas;
18396
- this._hadListener = true;
18371
+ this._target = target;
18372
+ this._addEventListener();
18397
18373
  }
18398
18374
  var _proto = WheelManager.prototype;
18399
18375
  /**
@@ -18414,35 +18390,24 @@ __decorate([
18414
18390
  };
18415
18391
  /**
18416
18392
  * @internal
18417
- */ _proto._onFocus = function _onFocus() {
18418
- if (!this._hadListener) {
18419
- this._canvas.addEventListener("wheel", this._onWheelEvent);
18420
- this._hadListener = true;
18421
- }
18393
+ */ _proto._addEventListener = function _addEventListener() {
18394
+ this._target.addEventListener("wheel", this._onWheelEvent);
18422
18395
  };
18423
18396
  /**
18424
18397
  * @internal
18425
- */ _proto._onBlur = function _onBlur() {
18426
- if (this._hadListener) {
18427
- this._canvas.removeEventListener("wheel", this._onWheelEvent);
18428
- this._nativeEvents.length = 0;
18429
- this._delta.set(0, 0, 0);
18430
- this._hadListener = false;
18431
- }
18398
+ */ _proto._removeEventListener = function _removeEventListener() {
18399
+ this._target.removeEventListener("wheel", this._onWheelEvent);
18400
+ this._nativeEvents.length = 0;
18401
+ this._delta.set(0, 0, 0);
18432
18402
  };
18433
18403
  /**
18434
18404
  * @internal
18435
18405
  */ _proto._destroy = function _destroy() {
18436
- if (this._hadListener) {
18437
- this._canvas.removeEventListener("wheel", this._onWheelEvent);
18438
- this._hadListener = false;
18439
- }
18406
+ this._removeEventListener();
18440
18407
  this._nativeEvents = null;
18441
- this._canvas = null;
18442
18408
  this._delta = null;
18443
18409
  };
18444
18410
  _proto._onWheelEvent = function _onWheelEvent(evt) {
18445
- evt.cancelable && evt.preventDefault();
18446
18411
  this._nativeEvents.push(evt);
18447
18412
  };
18448
18413
  return WheelManager;
@@ -18451,19 +18416,19 @@ __decorate([
18451
18416
  /**
18452
18417
  * InputManager manages device input such as mouse, touch, keyboard, etc.
18453
18418
  */ var InputManager = /*#__PURE__*/ function() {
18454
- function InputManager(engine) {
18419
+ function InputManager(engine, inputOptions) {
18455
18420
  /** Sometimes the input module will not be initialized, such as off-screen rendering. */ this._initialized = false;
18456
18421
  this._engine = engine;
18457
18422
  // @ts-ignore
18458
18423
  var canvas = engine._canvas._webCanvas;
18459
18424
  if (typeof OffscreenCanvas === "undefined" || !_instanceof(canvas, OffscreenCanvas)) {
18460
- this._wheelManager = new WheelManager(engine);
18461
- this._pointerManager = new PointerManager(engine);
18462
- this._keyboardManager = new KeyboardManager(engine);
18463
- this._onBlur = this._onBlur.bind(this);
18464
- window.addEventListener("blur", this._onBlur);
18465
- this._onFocus = this._onFocus.bind(this);
18466
- window.addEventListener("focus", this._onFocus);
18425
+ var _inputOptions, _inputOptions1, _inputOptions2;
18426
+ var _inputOptions_wheelTarget;
18427
+ this._wheelManager = new WheelManager(engine, (_inputOptions_wheelTarget = (_inputOptions = inputOptions) == null ? void 0 : _inputOptions.wheelTarget) != null ? _inputOptions_wheelTarget : canvas);
18428
+ var _inputOptions_pointerTarget;
18429
+ this._pointerManager = new PointerManager(engine, (_inputOptions_pointerTarget = (_inputOptions1 = inputOptions) == null ? void 0 : _inputOptions1.pointerTarget) != null ? _inputOptions_pointerTarget : canvas);
18430
+ var _inputOptions_keyboardTarget;
18431
+ this._keyboardManager = new KeyboardManager(engine, (_inputOptions_keyboardTarget = (_inputOptions2 = inputOptions) == null ? void 0 : _inputOptions2.keyboardTarget) != null ? _inputOptions_keyboardTarget : window);
18467
18432
  this._initialized = true;
18468
18433
  }
18469
18434
  }
@@ -18576,8 +18541,6 @@ __decorate([
18576
18541
  * @internal
18577
18542
  */ _proto._destroy = function _destroy() {
18578
18543
  if (this._initialized) {
18579
- window.removeEventListener("blur", this._onBlur);
18580
- window.removeEventListener("focus", this._onFocus);
18581
18544
  this._wheelManager._destroy();
18582
18545
  this._wheelManager = null;
18583
18546
  this._pointerManager._destroy();
@@ -18586,16 +18549,6 @@ __decorate([
18586
18549
  this._keyboardManager = null;
18587
18550
  }
18588
18551
  };
18589
- _proto._onBlur = function _onBlur() {
18590
- this._wheelManager._onBlur();
18591
- this._pointerManager._onBlur();
18592
- this._keyboardManager._onBlur();
18593
- };
18594
- _proto._onFocus = function _onFocus() {
18595
- this._wheelManager._onFocus();
18596
- this._pointerManager._onFocus();
18597
- this._keyboardManager._onFocus();
18598
- };
18599
18552
  _create_class(InputManager, [
18600
18553
  {
18601
18554
  key: "pointers",
@@ -18974,8 +18927,9 @@ var unlitVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#in
18974
18927
  }
18975
18928
  return;
18976
18929
  }
18930
+ ++hierarchy;
18977
18931
  for(var k1 in cacheMap){
18978
- this._recursiveDestroy(++hierarchy, cacheMap[k1]);
18932
+ this._recursiveDestroy(hierarchy, cacheMap[k1]);
18979
18933
  }
18980
18934
  };
18981
18935
  _proto._resizeCacheMapHierarchy = function _resizeCacheMapHierarchy(cacheMap, hierarchy, currentHierarchy, increaseHierarchy) {
@@ -19093,7 +19047,7 @@ ShaderPool.init();
19093
19047
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
19094
19048
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
19095
19049
  _this._textDefaultFont.isGCIgnored = true;
19096
- _this.inputManager = new InputManager(_assert_this_initialized(_this));
19050
+ _this.inputManager = new InputManager(_assert_this_initialized(_this), configuration.input);
19097
19051
  var xrDevice = configuration.xrDevice;
19098
19052
  if (xrDevice) {
19099
19053
  _this.xrManager = new XRManager();
@@ -21941,7 +21895,12 @@ var passNum = 0;
21941
21895
  if (componentA.instanceId === componentB.instanceId) {
21942
21896
  return dataA.material._priority - dataB.material._priority || componentA._distanceForSort - componentB._distanceForSort;
21943
21897
  } else {
21944
- return componentA._distanceForSort - componentB._distanceForSort;
21898
+ var distanceDiff = componentA._distanceForSort - componentB._distanceForSort;
21899
+ if (distanceDiff === 0) {
21900
+ return componentA.instanceId - componentB.instanceId;
21901
+ } else {
21902
+ return distanceDiff;
21903
+ }
21945
21904
  }
21946
21905
  };
21947
21906
  /**
@@ -21959,7 +21918,12 @@ var passNum = 0;
21959
21918
  if (componentA.instanceId === componentB.instanceId) {
21960
21919
  return dataA.material._priority - dataB.material._priority || componentB._distanceForSort - componentA._distanceForSort;
21961
21920
  } else {
21962
- return componentB._distanceForSort - componentA._distanceForSort;
21921
+ var distanceDiff = componentB._distanceForSort - componentA._distanceForSort;
21922
+ if (distanceDiff === 0) {
21923
+ return componentA.instanceId - componentB.instanceId;
21924
+ } else {
21925
+ return distanceDiff;
21926
+ }
21963
21927
  }
21964
21928
  };
21965
21929
  return RenderQueue;
@@ -23173,14 +23137,14 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23173
23137
  /** @internal */ _this._cameraIndex = -1;
23174
23138
  _this._priority = 0;
23175
23139
  _this._shaderData = new ShaderData(ShaderDataGroup.Camera);
23176
- _this._isProjMatSetting = false;
23140
+ _this._isCustomViewMatrix = false;
23141
+ _this._isCustomProjectionMatrix = false;
23177
23142
  _this._nearClipPlane = 0.1;
23178
23143
  _this._farClipPlane = 100;
23179
23144
  _this._fieldOfView = 45;
23180
23145
  _this._orthographicSize = 10;
23181
23146
  _this._isProjectionDirty = true;
23182
23147
  _this._isInvProjMatDirty = true;
23183
- _this._isFrustumProjectDirty = true;
23184
23148
  _this._customAspectRatio = undefined;
23185
23149
  _this._renderTarget = null;
23186
23150
  _this._depthBufferParams = new Vector4();
@@ -23192,7 +23156,7 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23192
23156
  _this._transform = transform;
23193
23157
  _this._isViewMatrixDirty = transform.registerWorldChangeFlag();
23194
23158
  _this._isInvViewProjDirty = transform.registerWorldChangeFlag();
23195
- _this._frustumViewChangeFlag = transform.registerWorldChangeFlag();
23159
+ _this._frustumChangeFlag = transform.registerWorldChangeFlag();
23196
23160
  _this._renderPipeline = new BasicRenderPipeline(_assert_this_initialized(_this));
23197
23161
  _this._addResourceReferCount(_this.shaderData, 1);
23198
23162
  _this._updatePixelViewport();
@@ -23204,16 +23168,22 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23204
23168
  }
23205
23169
  var _proto = Camera1.prototype;
23206
23170
  /**
23171
+ * Restore the view matrix to the world matrix of the entity.
23172
+ */ _proto.resetViewMatrix = function resetViewMatrix() {
23173
+ this._isCustomViewMatrix = false;
23174
+ this._viewMatrixChange();
23175
+ };
23176
+ /**
23207
23177
  * Restore the automatic calculation of projection matrix through fieldOfView, nearClipPlane and farClipPlane.
23208
23178
  */ _proto.resetProjectionMatrix = function resetProjectionMatrix() {
23209
- this._isProjMatSetting = false;
23210
- this._projMatChange();
23179
+ this._isCustomProjectionMatrix = false;
23180
+ this._projectionMatrixChange();
23211
23181
  };
23212
23182
  /**
23213
23183
  * Restore the automatic calculation of the aspect ratio through the viewport aspect ratio.
23214
23184
  */ _proto.resetAspectRatio = function resetAspectRatio() {
23215
23185
  this._customAspectRatio = undefined;
23216
- this._projMatChange();
23186
+ this._projectionMatrixChange();
23217
23187
  };
23218
23188
  /**
23219
23189
  * Transform a point from world space to viewport space.
@@ -23343,10 +23313,9 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23343
23313
  context.replacementShader = this._replacementShader;
23344
23314
  context.replacementTag = this._replacementSubShaderTag;
23345
23315
  // compute cull frustum.
23346
- if (this.enableFrustumCulling && (this._frustumViewChangeFlag.flag || this._isFrustumProjectDirty)) {
23316
+ if (this.enableFrustumCulling && this._frustumChangeFlag.flag) {
23347
23317
  this._frustum.calculateFromMatrix(virtualCamera.viewProjectionMatrix);
23348
- this._frustumViewChangeFlag.flag = false;
23349
- this._isFrustumProjectDirty = false;
23318
+ this._frustumChangeFlag.flag = false;
23350
23319
  }
23351
23320
  this._updateShaderData();
23352
23321
  // union scene and camera macro.
@@ -23401,7 +23370,7 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23401
23370
  this._renderPipeline = null;
23402
23371
  this._virtualCamera = null;
23403
23372
  this._shaderData = null;
23404
- this._frustumViewChangeFlag = null;
23373
+ this._frustumChangeFlag = null;
23405
23374
  this._transform = null;
23406
23375
  this._isViewMatrixDirty = null;
23407
23376
  this._isInvViewProjDirty = null;
@@ -23423,11 +23392,16 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23423
23392
  var viewport = this._viewport;
23424
23393
  this._pixelViewport.set(viewport.x * width, viewport.y * height, viewport.z * width, viewport.w * height);
23425
23394
  };
23426
- _proto._projMatChange = function _projMatChange() {
23427
- this._isFrustumProjectDirty = true;
23395
+ _proto._viewMatrixChange = function _viewMatrixChange() {
23396
+ this._isViewMatrixDirty.flag = true;
23397
+ this._isInvViewProjDirty.flag = true;
23398
+ this._frustumChangeFlag.flag = true;
23399
+ };
23400
+ _proto._projectionMatrixChange = function _projectionMatrixChange() {
23428
23401
  this._isProjectionDirty = true;
23429
23402
  this._isInvProjMatDirty = true;
23430
23403
  this._isInvViewProjDirty.flag = true;
23404
+ this._frustumChangeFlag.flag = true;
23431
23405
  };
23432
23406
  _proto._innerViewportToWorldPoint = function _innerViewportToWorldPoint(x, y, z, invViewProjMat, out) {
23433
23407
  // Depth is a normalized value, 0 is nearPlane, 1 is farClipPlane.
@@ -23470,7 +23444,7 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23470
23444
  _proto._onPixelViewportChanged = function _onPixelViewportChanged() {
23471
23445
  this._updatePixelViewport();
23472
23446
  var _this__customAspectRatio;
23473
- (_this__customAspectRatio = this._customAspectRatio) != null ? _this__customAspectRatio : this._projMatChange();
23447
+ (_this__customAspectRatio = this._customAspectRatio) != null ? _this__customAspectRatio : this._projectionMatrixChange();
23474
23448
  };
23475
23449
  _create_class(Camera1, [
23476
23450
  {
@@ -23490,7 +23464,7 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23490
23464
  },
23491
23465
  set: function set(value) {
23492
23466
  this._nearClipPlane = value;
23493
- this._projMatChange();
23467
+ this._projectionMatrixChange();
23494
23468
  }
23495
23469
  },
23496
23470
  {
@@ -23502,7 +23476,7 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23502
23476
  },
23503
23477
  set: function set(value) {
23504
23478
  this._farClipPlane = value;
23505
- this._projMatChange();
23479
+ this._projectionMatrixChange();
23506
23480
  }
23507
23481
  },
23508
23482
  {
@@ -23514,7 +23488,7 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23514
23488
  },
23515
23489
  set: function set(value) {
23516
23490
  this._fieldOfView = value;
23517
- this._projMatChange();
23491
+ this._projectionMatrixChange();
23518
23492
  }
23519
23493
  },
23520
23494
  {
@@ -23529,7 +23503,7 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23529
23503
  },
23530
23504
  set: function set(value) {
23531
23505
  this._customAspectRatio = value;
23532
- this._projMatChange();
23506
+ this._projectionMatrixChange();
23533
23507
  }
23534
23508
  },
23535
23509
  {
@@ -23581,7 +23555,12 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23581
23555
  },
23582
23556
  set: function set(value) {
23583
23557
  this._virtualCamera.isOrthographic = value;
23584
- this._projMatChange();
23558
+ this._projectionMatrixChange();
23559
+ if (value) {
23560
+ this.shaderData.enableMacro("CAMERA_ORTHOGRAPHIC");
23561
+ } else {
23562
+ this.shaderData.disableMacro("CAMERA_ORTHOGRAPHIC");
23563
+ }
23585
23564
  }
23586
23565
  },
23587
23566
  {
@@ -23593,7 +23572,7 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23593
23572
  },
23594
23573
  set: function set(value) {
23595
23574
  this._orthographicSize = value;
23596
- this._projMatChange();
23575
+ this._projectionMatrixChange();
23597
23576
  }
23598
23577
  },
23599
23578
  {
@@ -23602,22 +23581,31 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23602
23581
  * View matrix.
23603
23582
  */ function get() {
23604
23583
  var viewMatrix = this._virtualCamera.viewMatrix;
23605
- if (this._isViewMatrixDirty.flag) {
23606
- this._isViewMatrixDirty.flag = false;
23607
- // Ignore scale.
23608
- var transform = this._transform;
23609
- Matrix.rotationTranslation(transform.worldRotationQuaternion, transform.worldPosition, viewMatrix);
23610
- viewMatrix.invert();
23611
- }
23584
+ if (!this._isViewMatrixDirty.flag || this._isCustomViewMatrix) {
23585
+ return viewMatrix;
23586
+ }
23587
+ this._isViewMatrixDirty.flag = false;
23588
+ // Ignore scale
23589
+ var transform = this._transform;
23590
+ Matrix.rotationTranslation(transform.worldRotationQuaternion, transform.worldPosition, viewMatrix);
23591
+ viewMatrix.invert();
23612
23592
  return viewMatrix;
23593
+ },
23594
+ set: function set(value) {
23595
+ this._virtualCamera.viewMatrix.copyFrom(value);
23596
+ this._isCustomViewMatrix = true;
23597
+ this._viewMatrixChange();
23613
23598
  }
23614
23599
  },
23615
23600
  {
23616
23601
  key: "projectionMatrix",
23617
- get: function get() {
23602
+ get: /**
23603
+ * The projection matrix is ​​calculated by the relevant parameters of the camera by default.
23604
+ * If it is manually set, the manual value will be maintained. Call resetProjectionMatrix() to restore it.
23605
+ */ function get() {
23618
23606
  var virtualCamera = this._virtualCamera;
23619
23607
  var projectionMatrix = virtualCamera.projectionMatrix;
23620
- if (!this._isProjectionDirty || this._isProjMatSetting) {
23608
+ if (!this._isProjectionDirty || this._isCustomProjectionMatrix) {
23621
23609
  return projectionMatrix;
23622
23610
  }
23623
23611
  this._isProjectionDirty = false;
@@ -23631,13 +23619,10 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23631
23619
  }
23632
23620
  return projectionMatrix;
23633
23621
  },
23634
- set: /**
23635
- * The projection matrix is ​​calculated by the relevant parameters of the camera by default.
23636
- * If it is manually set, the manual value will be maintained. Call resetProjectionMatrix() to restore it.
23637
- */ function set(value) {
23622
+ set: function set(value) {
23638
23623
  this._virtualCamera.projectionMatrix.copyFrom(value);
23639
- this._isProjMatSetting = true;
23640
- this._projMatChange();
23624
+ this._isCustomProjectionMatrix = true;
23625
+ this._projectionMatrixChange();
23641
23626
  }
23642
23627
  },
23643
23628
  {
@@ -23698,7 +23683,7 @@ __decorate([
23698
23683
  ], Camera.prototype, "_cameraIndex", void 0);
23699
23684
  __decorate([
23700
23685
  ignoreClone
23701
- ], Camera.prototype, "_frustumViewChangeFlag", void 0);
23686
+ ], Camera.prototype, "_frustumChangeFlag", void 0);
23702
23687
  __decorate([
23703
23688
  ignoreClone
23704
23689
  ], Camera.prototype, "_transform", void 0);