@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.
@@ -600,7 +600,14 @@ var Utils = /*#__PURE__*/ function() {
600
600
  * @param url - The url to be judged.
601
601
  * @returns Whether the url is absolute url.
602
602
  */ Utils.isAbsoluteUrl = function isAbsoluteUrl(url) {
603
- return /^(?:http|blob|data:|\/)/.test(url);
603
+ return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
604
+ };
605
+ /**
606
+ * Judge whether the url is base64 url.
607
+ * @param url - The url to be judged.
608
+ * @returns Whether the url is base64 url.
609
+ */ Utils.isBase64Url = function isBase64Url(url) {
610
+ return /^data:.*,.*$/i.test(url);
604
611
  };
605
612
  /**
606
613
  * Get the values of an object.
@@ -618,7 +625,10 @@ var Utils = /*#__PURE__*/ function() {
618
625
  if (Utils.isAbsoluteUrl(relativeUrl)) {
619
626
  return relativeUrl;
620
627
  }
621
- return baseUrl.substring(0, baseUrl.lastIndexOf("/") + 1) + this._formatRelativePath(relativeUrl);
628
+ if (Utils.isBase64Url(relativeUrl)) {
629
+ return relativeUrl;
630
+ }
631
+ return relativeUrl ? baseUrl.replace(/\/+$/, "") + "/" + relativeUrl.replace(/^\/+/, "") : baseUrl;
622
632
  };
623
633
  /**
624
634
  * @internal
@@ -3174,7 +3184,7 @@ function _extends() {
3174
3184
  return _extends.apply(this, arguments);
3175
3185
  }
3176
3186
 
3177
- var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;"; // eslint-disable-line
3187
+ var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;uniform vec3 camera_Forward;"; // eslint-disable-line
3178
3188
 
3179
3189
  var common = "#define GLSLIFY 1\n#define PI 3.14159265359\n#define RECIPROCAL_PI 0.31830988618\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate( a ) clamp( a, 0.0, 1.0 )\nfloat pow2(float x){return x*x;}vec4 RGBMToLinear(vec4 value,float maxRange){return vec4(value.rgb*value.a*maxRange,1.0);}vec4 gammaToLinear(vec4 srgbIn){return vec4(pow(srgbIn.rgb,vec3(2.2)),srgbIn.a);}vec4 linearToGamma(vec4 linearIn){return vec4(pow(linearIn.rgb,vec3(1.0/2.2)),linearIn.a);}uniform vec4 camera_DepthBufferParams;float remapDepthBufferLinear01(float z){return 1.0/(camera_DepthBufferParams.x*z+camera_DepthBufferParams.y);}\n#ifdef GRAPHICS_API_WEBGL2\n#define INVERSE_MAT(mat) inverse(mat)\n#else\nmat2 inverseMat(mat2 m){return mat2(m[1][1],-m[0][1],-m[1][0],m[0][0])/(m[0][0]*m[1][1]-m[0][1]*m[1][0]);}mat3 inverseMat(mat3 m){float a00=m[0][0],a01=m[0][1],a02=m[0][2];float a10=m[1][0],a11=m[1][1],a12=m[1][2];float a20=m[2][0],a21=m[2][1],a22=m[2][2];float b01=a22*a11-a12*a21;float b11=-a22*a10+a12*a20;float b21=a21*a10-a11*a20;float det=a00*b01+a01*b11+a02*b21;return mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),b11,(a22*a00-a02*a20),(-a12*a00+a02*a10),b21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;}mat4 inverseMat(mat4 m){float a00=m[0][0],a01=m[0][1],a02=m[0][2],a03=m[0][3],a10=m[1][0],a11=m[1][1],a12=m[1][2],a13=m[1][3],a20=m[2][0],a21=m[2][1],a22=m[2][2],a23=m[2][3],a30=m[3][0],a31=m[3][1],a32=m[3][2],a33=m[3][3],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return mat4(a11*b11-a12*b10+a13*b09,a02*b10-a01*b11-a03*b09,a31*b05-a32*b04+a33*b03,a22*b04-a21*b05-a23*b03,a12*b08-a10*b11-a13*b07,a00*b11-a02*b08+a03*b07,a32*b02-a30*b05-a33*b01,a20*b05-a22*b02+a23*b01,a10*b10-a11*b08+a13*b06,a01*b08-a00*b10-a03*b06,a30*b04-a31*b02+a33*b00,a21*b02-a20*b04-a23*b00,a11*b07-a10*b09-a12*b06,a00*b09-a01*b07+a02*b06,a31*b01-a30*b03-a32*b00,a20*b03-a21*b01+a22*b00)/det;}\n#define INVERSE_MAT(mat) inverseMat(mat)\n#endif\n"; // eslint-disable-line
3180
3190
 
@@ -3224,7 +3234,7 @@ var mobile_material_frag = "#define GLSLIFY 1\nuniform vec4 material_EmissiveCol
3224
3234
 
3225
3235
  var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission=material_EmissiveColor;vec4 diffuse=material_BaseColor;vec4 specular=material_SpecularColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nvec4 emissiveTextureColor=texture2D(material_EmissiveTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nemissiveTextureColor=gammaToLinear(emissiveTextureColor);\n#endif\nemission*=emissiveTextureColor;\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 diffuseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ndiffuseTextureColor=gammaToLinear(diffuseTextureColor);\n#endif\ndiffuse*=diffuseTextureColor;\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\ndiffuse*=v_color;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\nvec4 specularTextureColor=texture2D(material_SpecularTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularTextureColor=gammaToLinear(specularTextureColor);\n#endif\nspecular*=specularTextureColor;\n#endif\nambient=vec4(scene_EnvMapLight.diffuse*scene_EnvMapLight.diffuseIntensity,1.0)*diffuse;"; // eslint-disable-line
3226
3236
 
3227
- var begin_viewdir_frag = "#define GLSLIFY 1\n#ifdef MATERIAL_NEED_WORLD_POS\nvec3 V=normalize(camera_Position-v_pos);\n#endif\n"; // eslint-disable-line
3237
+ var begin_viewdir_frag = "#define GLSLIFY 1\n#ifdef CAMERA_ORTHOGRAPHIC\nvec3 V=-camera_Forward;\n#else\n#ifdef MATERIAL_NEED_WORLD_POS\nvec3 V=normalize(camera_Position-v_pos);\n#endif\n#endif\n"; // eslint-disable-line
3228
3238
 
3229
3239
  var mobile_blinnphong_frag = "#define GLSLIFY 1\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nmat3 tbn=getTBN(gl_FrontFacing);vec3 N=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,gl_FrontFacing);\n#else\nvec3 N=getNormal(gl_FrontFacing);\n#endif\nvec3 lightDiffuse=vec3(0.0,0.0,0.0);vec3 lightSpecular=vec3(0.0,0.0,0.0);float shadowAttenuation=1.0;\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nshadowAttenuation=1.0;\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nshadowAttenuation*=sampleShadowMap();\n#endif\nDirectLight directionalLight;for(int i=0;i<SCENE_DIRECT_LIGHT_COUNT;i++){if(!isRendererCulledByLight(renderer_Layer.xy,scene_DirectLightCullingMask[i])){directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==0){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];float d=max(dot(N,-directionalLight.direction),0.0);lightDiffuse+=directionalLight.color*d;vec3 halfDir=normalize(V-directionalLight.direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess);lightSpecular+=directionalLight.color*s;}}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(!isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i])){pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];vec3 direction=v_pos-pointLight.position;float dist=length(direction);direction/=dist;float decay=clamp(1.0-pow(dist/pointLight.distance,4.0),0.0,1.0);float d=max(dot(N,-direction),0.0)*decay;lightDiffuse+=pointLight.color*d;vec3 halfDir=normalize(V-direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decay;lightSpecular+=pointLight.color*s;}}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nSpotLight spotLight;for(int i=0;i<SCENE_SPOT_LIGHT_COUNT;i++){if(!isRendererCulledByLight(renderer_Layer.xy,scene_SpotLightCullingMask[i])){spotLight.color=scene_SpotLightColor[i];spotLight.position=scene_SpotLightPosition[i];spotLight.direction=scene_SpotLightDirection[i];spotLight.distance=scene_SpotLightDistance[i];spotLight.angleCos=scene_SpotLightAngleCos[i];spotLight.penumbraCos=scene_SpotLightPenumbraCos[i];vec3 direction=spotLight.position-v_pos;float lightDistance=length(direction);direction/=lightDistance;float angleCos=dot(direction,-spotLight.direction);float decay=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayTotal=decay*spotEffect;float d=max(dot(N,direction),0.0)*decayTotal;lightDiffuse+=spotLight.color*d;vec3 halfDir=normalize(V+direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decayTotal;lightSpecular+=spotLight.color*s;}}\n#endif\ndiffuse*=vec4(lightDiffuse,1.0);specular*=vec4(lightSpecular,1.0);\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(diffuse.a<material_AlphaCutoff){discard;}\n#endif\n"; // eslint-disable-line
3230
3240
 
@@ -3262,7 +3272,7 @@ var noise_simplex_4D = "#define GLSLIFY 1\nvec4 grad4(float j,vec4 ip){const vec
3262
3272
 
3263
3273
  var pbr_frag_define = "#define GLSLIFY 1\n#define MIN_PERCEPTUAL_ROUGHNESS 0.045\n#define MIN_ROUGHNESS 0.002025\nuniform float material_AlphaCutoff;uniform vec4 material_BaseColor;uniform float material_Metal;uniform float material_Roughness;uniform float material_IOR;uniform vec3 material_PBRSpecularColor;uniform float material_Glossiness;uniform vec3 material_EmissiveColor;uniform float material_NormalIntensity;uniform float material_OcclusionIntensity;uniform float material_OcclusionTextureCoord;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nuniform float material_ClearCoat;uniform float material_ClearCoatRoughness;\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nuniform sampler2D material_ClearCoatTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nuniform sampler2D material_ClearCoatRoughnessTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\nuniform sampler2D material_ClearCoatNormalTexture;\n#endif\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nuniform vec3 material_AnisotropyInfo;\n#ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\nuniform sampler2D material_AnisotropyTexture;\n#endif\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nuniform sampler2D material_BaseTexture;\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nuniform sampler2D material_NormalTexture;\n#endif\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nuniform sampler2D material_EmissiveTexture;\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nuniform sampler2D material_RoughnessMetallicTexture;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nuniform sampler2D material_SpecularGlossinessTexture;\n#endif\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\nuniform sampler2D material_OcclusionTexture;\n#endif\nstruct ReflectedLight{vec3 directDiffuse;vec3 directSpecular;vec3 indirectDiffuse;vec3 indirectSpecular;};struct Geometry{vec3 position;vec3 normal;vec3 viewDir;float dotNV;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nvec3 clearCoatNormal;float clearCoatDotNV;\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 anisotropicT;vec3 anisotropicB;vec3 anisotropicN;float anisotropy;\n#endif\n};struct Material{vec3 diffuseColor;float roughness;vec3 specularColor;float opacity;float f0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoat;float clearCoatRoughness;\n#endif\n};"; // eslint-disable-line
3264
3274
 
3265
- var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecularOcclusion(float ambientOcclusion,float roughness,float dotNV){return saturate(pow(dotNV+ambientOcclusion,exp2(-16.0*roughness-1.0))-1.0+ambientOcclusion);}float getAARoughnessFactor(vec3 normal){\n#ifdef HAS_DERIVATIVES\nvec3 dxy=max(abs(dFdx(normal)),abs(dFdy(normal)));return MIN_PERCEPTUAL_ROUGHNESS+max(max(dxy.x,dxy.y),dxy.z);\n#else\nreturn MIN_PERCEPTUAL_ROUGHNESS;\n#endif\n}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 getAnisotropicBentNormal(Geometry geometry,vec3 n,float roughness){vec3 anisotropyDirection=geometry.anisotropy>=0.0 ? geometry.anisotropicB : geometry.anisotropicT;vec3 anisotropicTangent=cross(anisotropyDirection,geometry.viewDir);vec3 anisotropicNormal=cross(anisotropicTangent,anisotropyDirection);vec3 bentNormal=normalize(mix(n,anisotropicNormal,abs(geometry.anisotropy)*saturate(5.0*roughness)));return bentNormal;}\n#endif\nvoid initGeometry(out Geometry geometry,bool isFrontFacing){geometry.position=v_pos;geometry.viewDir=normalize(camera_Position-v_pos);\n#if defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY)\nmat3 tbn=getTBN(isFrontFacing);\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\ngeometry.normal=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.normal=getNormal(isFrontFacing);\n#endif\ngeometry.dotNV=saturate(dot(geometry.normal,geometry.viewDir));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\ngeometry.clearCoatNormal=getNormalByNormalTexture(tbn,material_ClearCoatNormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.clearCoatNormal=getNormal(isFrontFacing);\n#endif\ngeometry.clearCoatDotNV=saturate(dot(geometry.clearCoatNormal,geometry.viewDir));\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat anisotropy=material_AnisotropyInfo.z;vec3 anisotropicDirection=vec3(material_AnisotropyInfo.xy,0.0);\n#ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\nvec3 anisotropyTextureInfo=texture2D(material_AnisotropyTexture,v_uv).rgb;anisotropy*=anisotropyTextureInfo.b;anisotropicDirection.xy*=anisotropyTextureInfo.rg*2.0-1.0;\n#endif\ngeometry.anisotropy=anisotropy;geometry.anisotropicT=normalize(tbn*anisotropicDirection);geometry.anisotropicB=normalize(cross(geometry.normal,geometry.anisotropicT));\n#endif\n}void initMaterial(out Material material,inout Geometry geometry){vec4 baseColor=material_BaseColor;float metal=material_Metal;float roughness=material_Roughness;vec3 specularColor=material_PBRSpecularColor;float glossiness=material_Glossiness;float alphaCutoff=material_AlphaCutoff;float f0=pow2((material_IOR-1.0)/(material_IOR+1.0));material.f0=f0;\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 baseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nbaseTextureColor=gammaToLinear(baseTextureColor);\n#endif\nbaseColor*=baseTextureColor;\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nbaseColor*=v_color;\n#endif\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(baseColor.a<alphaCutoff){discard;}\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nvec4 metalRoughMapColor=texture2D(material_RoughnessMetallicTexture,v_uv);roughness*=metalRoughMapColor.g;metal*=metalRoughMapColor.b;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nvec4 specularGlossinessColor=texture2D(material_SpecularGlossinessTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularGlossinessColor=gammaToLinear(specularGlossinessColor);\n#endif\nspecularColor*=specularGlossinessColor.rgb;glossiness*=specularGlossinessColor.a;\n#endif\n#ifdef IS_METALLIC_WORKFLOW\nmaterial.diffuseColor=baseColor.rgb*(1.0-metal);material.specularColor=mix(vec3(f0),baseColor.rgb,metal);material.roughness=roughness;\n#else\nfloat specularStrength=max(max(specularColor.r,specularColor.g),specularColor.b);material.diffuseColor=baseColor.rgb*(1.0-specularStrength);material.specularColor=specularColor;material.roughness=1.0-glossiness;\n#endif\nmaterial.roughness=max(material.roughness,getAARoughnessFactor(geometry.normal));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nmaterial.clearCoat=material_ClearCoat;material.clearCoatRoughness=material_ClearCoatRoughness;\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nmaterial.clearCoat*=texture2D(material_ClearCoatTexture,v_uv).r;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nmaterial.clearCoatRoughness*=texture2D(material_ClearCoatRoughnessTexture,v_uv).g;\n#endif\nmaterial.clearCoat=saturate(material.clearCoat);material.clearCoatRoughness=max(material.clearCoatRoughness,getAARoughnessFactor(geometry.clearCoatNormal));\n#endif\n#ifdef MATERIAL_IS_TRANSPARENT\nmaterial.opacity=baseColor.a;\n#else\nmaterial.opacity=1.0;\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\ngeometry.anisotropicN=getAnisotropicBentNormal(geometry,geometry.normal,material.roughness);\n#endif\n}\n#include <brdf>\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n"; // eslint-disable-line
3275
+ var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecularOcclusion(float ambientOcclusion,float roughness,float dotNV){return saturate(pow(dotNV+ambientOcclusion,exp2(-16.0*roughness-1.0))-1.0+ambientOcclusion);}float getAARoughnessFactor(vec3 normal){\n#ifdef HAS_DERIVATIVES\nvec3 dxy=max(abs(dFdx(normal)),abs(dFdy(normal)));return MIN_PERCEPTUAL_ROUGHNESS+max(max(dxy.x,dxy.y),dxy.z);\n#else\nreturn MIN_PERCEPTUAL_ROUGHNESS;\n#endif\n}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 getAnisotropicBentNormal(Geometry geometry,vec3 n,float roughness){vec3 anisotropyDirection=geometry.anisotropy>=0.0 ? geometry.anisotropicB : geometry.anisotropicT;vec3 anisotropicTangent=cross(anisotropyDirection,geometry.viewDir);vec3 anisotropicNormal=cross(anisotropicTangent,anisotropyDirection);vec3 bentNormal=normalize(mix(n,anisotropicNormal,abs(geometry.anisotropy)*saturate(5.0*roughness)));return bentNormal;}\n#endif\nvoid initGeometry(out Geometry geometry,bool isFrontFacing){geometry.position=v_pos;\n#ifdef CAMERA_ORTHOGRAPHIC\ngeometry.viewDir=-camera_Forward;\n#else\ngeometry.viewDir=normalize(camera_Position-v_pos);\n#endif\n#if defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) || defined(MATERIAL_ENABLE_ANISOTROPY)\nmat3 tbn=getTBN(isFrontFacing);\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\ngeometry.normal=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.normal=getNormal(isFrontFacing);\n#endif\ngeometry.dotNV=saturate(dot(geometry.normal,geometry.viewDir));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\ngeometry.clearCoatNormal=getNormalByNormalTexture(tbn,material_ClearCoatNormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.clearCoatNormal=getNormal(isFrontFacing);\n#endif\ngeometry.clearCoatDotNV=saturate(dot(geometry.clearCoatNormal,geometry.viewDir));\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat anisotropy=material_AnisotropyInfo.z;vec3 anisotropicDirection=vec3(material_AnisotropyInfo.xy,0.0);\n#ifdef MATERIAL_HAS_ANISOTROPY_TEXTURE\nvec3 anisotropyTextureInfo=texture2D(material_AnisotropyTexture,v_uv).rgb;anisotropy*=anisotropyTextureInfo.b;anisotropicDirection.xy*=anisotropyTextureInfo.rg*2.0-1.0;\n#endif\ngeometry.anisotropy=anisotropy;geometry.anisotropicT=normalize(tbn*anisotropicDirection);geometry.anisotropicB=normalize(cross(geometry.normal,geometry.anisotropicT));\n#endif\n}void initMaterial(out Material material,inout Geometry geometry){vec4 baseColor=material_BaseColor;float metal=material_Metal;float roughness=material_Roughness;vec3 specularColor=material_PBRSpecularColor;float glossiness=material_Glossiness;float alphaCutoff=material_AlphaCutoff;float f0=pow2((material_IOR-1.0)/(material_IOR+1.0));material.f0=f0;\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 baseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nbaseTextureColor=gammaToLinear(baseTextureColor);\n#endif\nbaseColor*=baseTextureColor;\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nbaseColor*=v_color;\n#endif\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(baseColor.a<alphaCutoff){discard;}\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nvec4 metalRoughMapColor=texture2D(material_RoughnessMetallicTexture,v_uv);roughness*=metalRoughMapColor.g;metal*=metalRoughMapColor.b;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nvec4 specularGlossinessColor=texture2D(material_SpecularGlossinessTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularGlossinessColor=gammaToLinear(specularGlossinessColor);\n#endif\nspecularColor*=specularGlossinessColor.rgb;glossiness*=specularGlossinessColor.a;\n#endif\n#ifdef IS_METALLIC_WORKFLOW\nmaterial.diffuseColor=baseColor.rgb*(1.0-metal);material.specularColor=mix(vec3(f0),baseColor.rgb,metal);material.roughness=roughness;\n#else\nfloat specularStrength=max(max(specularColor.r,specularColor.g),specularColor.b);material.diffuseColor=baseColor.rgb*(1.0-specularStrength);material.specularColor=specularColor;material.roughness=1.0-glossiness;\n#endif\nmaterial.roughness=max(material.roughness,getAARoughnessFactor(geometry.normal));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nmaterial.clearCoat=material_ClearCoat;material.clearCoatRoughness=material_ClearCoatRoughness;\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nmaterial.clearCoat*=texture2D(material_ClearCoatTexture,v_uv).r;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nmaterial.clearCoatRoughness*=texture2D(material_ClearCoatRoughnessTexture,v_uv).g;\n#endif\nmaterial.clearCoat=saturate(material.clearCoat);material.clearCoatRoughness=max(material.clearCoatRoughness,getAARoughnessFactor(geometry.clearCoatNormal));\n#endif\n#ifdef MATERIAL_IS_TRANSPARENT\nmaterial.opacity=baseColor.a;\n#else\nmaterial.opacity=1.0;\n#endif\n#ifdef MATERIAL_ENABLE_ANISOTROPY\ngeometry.anisotropicN=getAnisotropicBentNormal(geometry,geometry.normal,material.roughness);\n#endif\n}\n#include <brdf>\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n"; // eslint-disable-line
3266
3276
 
3267
3277
  var brdf = "#define GLSLIFY 1\nfloat F_Schlick(float f0,float dotLH){return f0+0.96*(pow(1.0-dotLH,5.0));}vec3 F_Schlick(vec3 specularColor,float dotLH){float fresnel=exp2((-5.55473*dotLH-6.98316)*dotLH);return(1.0-specularColor)*fresnel+specularColor;}float G_GGX_SmithCorrelated(float alpha,float dotNL,float dotNV){float a2=pow2(alpha);float gv=dotNL*sqrt(a2+(1.0-a2)*pow2(dotNV));float gl=dotNV*sqrt(a2+(1.0-a2)*pow2(dotNL));return 0.5/max(gv+gl,EPSILON);}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat G_GGX_SmithCorrelated_Anisotropic(float at,float ab,float ToV,float BoV,float ToL,float BoL,float NoV,float NoL){float lambdaV=NoL*length(vec3(at*ToV,ab*BoV,NoV));float lambdaL=NoV*length(vec3(at*ToL,ab*BoL,NoL));return 0.5/max(lambdaV+lambdaL,EPSILON);}\n#endif\nfloat D_GGX(float alpha,float dotNH){float a2=pow2(alpha);float denom=pow2(dotNH)*(a2-1.0)+1.0;return RECIPROCAL_PI*a2/pow2(denom);}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nfloat D_GGX_Anisotropic(float at,float ab,float ToH,float BoH,float NoH){float a2=at*ab;highp vec3 d=vec3(ab*ToH,at*BoH,a2*NoH);highp float d2=dot(d,d);float b2=a2/d2;return a2*b2*b2*RECIPROCAL_PI;}\n#endif\nvec3 isotropicLobe(vec3 specularColor,float alpha,float dotNV,float dotNL,float dotNH,float dotLH){vec3 F=F_Schlick(specularColor,dotLH);float D=D_GGX(alpha,dotNH);float G=G_GGX_SmithCorrelated(alpha,dotNL,dotNV);return F*(G*D);}\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nvec3 anisotropicLobe(vec3 h,vec3 l,Geometry geometry,vec3 specularColor,float alpha,float dotNV,float dotNL,float dotNH,float dotLH){vec3 t=geometry.anisotropicT;vec3 b=geometry.anisotropicB;vec3 v=geometry.viewDir;float dotTV=dot(t,v);float dotBV=dot(b,v);float dotTL=dot(t,l);float dotBL=dot(b,l);float dotTH=dot(t,h);float dotBH=dot(b,h);float at=max(alpha*(1.0+geometry.anisotropy),MIN_ROUGHNESS);float ab=max(alpha*(1.0-geometry.anisotropy),MIN_ROUGHNESS);vec3 F=F_Schlick(specularColor,dotLH);float D=D_GGX_Anisotropic(at,ab,dotTH,dotBH,dotNH);float G=G_GGX_SmithCorrelated_Anisotropic(at,ab,dotTV,dotBV,dotTL,dotBL,dotNV,dotNL);return F*(G*D);}\n#endif\nvec3 BRDF_Specular_GGX(vec3 incidentDirection,Geometry geometry,vec3 normal,vec3 specularColor,float roughness){float alpha=pow2(roughness);vec3 halfDir=normalize(incidentDirection+geometry.viewDir);float dotNL=saturate(dot(normal,incidentDirection));float dotNV=saturate(dot(normal,geometry.viewDir));float dotNH=saturate(dot(normal,halfDir));float dotLH=saturate(dot(incidentDirection,halfDir));\n#ifdef MATERIAL_ENABLE_ANISOTROPY\nreturn anisotropicLobe(halfDir,incidentDirection,geometry,specularColor,alpha,dotNV,dotNL,dotNH,dotLH);\n#else\nreturn isotropicLobe(specularColor,alpha,dotNV,dotNL,dotNH,dotLH);\n#endif\n}vec3 BRDF_Diffuse_Lambert(vec3 diffuseColor){return RECIPROCAL_PI*diffuseColor;}"; // eslint-disable-line
3268
3278
 
@@ -3398,7 +3408,11 @@ var ShaderFactory = /*#__PURE__*/ function() {
3398
3408
  }
3399
3409
  ShaderLib[includeName] = includeSource;
3400
3410
  };
3401
- ShaderFactory.parseIncludes = function parseIncludes(src) {
3411
+ /**
3412
+ * @param regex The default regex is for engine's builtin glsl `#include` syntax,
3413
+ * since `ShaderLab` use the same parsing function but different syntax for `#include` --- `/^[ \t]*#include +"([\w\d.]+)"/gm`
3414
+ */ ShaderFactory.parseIncludes = function parseIncludes(src, regex) {
3415
+ if (regex === void 0) regex = /^[ \t]*#include +<([\w\d.]+)>/gm;
3402
3416
  var replace = function replace(match, slice) {
3403
3417
  var replace = ShaderLib[slice];
3404
3418
  if (replace === undefined) {
@@ -3407,7 +3421,6 @@ var ShaderFactory = /*#__PURE__*/ function() {
3407
3421
  }
3408
3422
  return ShaderFactory.parseIncludes(replace);
3409
3423
  };
3410
- var regex = /^[ \t]*#include +<([\w\d.]+)>/gm;
3411
3424
  return src.replace(regex, replace);
3412
3425
  };
3413
3426
  /**
@@ -6389,7 +6402,7 @@ SlicedSpriteAssembler = __decorate([
6389
6402
  _this._byteLength = byteLength;
6390
6403
  _this._platformBuffer = engine._hardwareRenderer.createPlatformBuffer(type, byteLength, bufferUsage, data);
6391
6404
  if (readable) {
6392
- var buffer = (data.constructor === ArrayBuffer ? data : data.buffer).slice(0, byteLength);
6405
+ var buffer = data.constructor === ArrayBuffer ? data.slice(0) : data.buffer.slice(data.byteOffset, data.byteOffset + byteLength);
6393
6406
  _this._data = new Uint8Array(buffer);
6394
6407
  }
6395
6408
  }
@@ -12884,6 +12897,9 @@ var /**
12884
12897
  var baseline = Math.ceil(context.measureText(TextUtils._measureBaseline).width);
12885
12898
  var height = baseline * TextUtils._heightMultiplier;
12886
12899
  baseline = TextUtils._baselineMultiplier * baseline | 0;
12900
+ var _extendHeight = TextUtils._extendHeight;
12901
+ height += _extendHeight;
12902
+ baseline += _extendHeight * 0.5;
12887
12903
  canvas.width = width;
12888
12904
  canvas.height = height;
12889
12905
  context.font = fontString;
@@ -12918,6 +12934,7 @@ var /**
12918
12934
  }
12919
12935
  if (top !== -1 && bottom !== -1) {
12920
12936
  ascent = baseline - top;
12937
+ // Baseline belong to descent
12921
12938
  descent = bottom - baseline + 1;
12922
12939
  size = ascent + descent;
12923
12940
  }
@@ -12994,9 +13011,8 @@ var /**
12994
13011
  ];
12995
13012
  })();
12996
13013
  (function() {
12997
- // _heightMultiplier used to measure the height of text, but in miniprogram performance is different from h5.
12998
- // so can set _heightMultiplier to adapt miniprogram, the larger the value, the worse the performance.
12999
- /** @internal */ TextUtils._heightMultiplier = 2;
13014
+ // _extendHeight used to extend the height of canvas, because in miniprogram performance is different from h5.
13015
+ /** @internal */ TextUtils._extendHeight = 0;
13000
13016
  })();
13001
13017
  (function() {
13002
13018
  /** These characters are all tall to help calculate the height required for text. */ TextUtils._measureString = "|\xc9q\xc5";
@@ -13004,6 +13020,9 @@ var /**
13004
13020
  (function() {
13005
13021
  TextUtils._measureBaseline = "M";
13006
13022
  })();
13023
+ (function() {
13024
+ TextUtils._heightMultiplier = 2;
13025
+ })();
13007
13026
  (function() {
13008
13027
  TextUtils._baselineMultiplier = 1.4;
13009
13028
  })();
@@ -14762,6 +14781,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData1) {
14762
14781
  AssetType[/** Cube Compress Texture. */ "KTXCube"] = "KTXCube";
14763
14782
  AssetType[/** KTX2 Compress Texture */ "KTX2"] = "KTX2";
14764
14783
  AssetType[/** Sprite. */ "Sprite"] = "Sprite";
14784
+ AssetType[/** PrimitiveMesh. */ "PrimitiveMesh"] = "PrimitiveMesh";
14765
14785
  AssetType[/** Sprite Atlas. */ "SpriteAtlas"] = "SpriteAtlas";
14766
14786
  AssetType[/** Ambient light. */ "Env"] = "Environment";
14767
14787
  AssetType[/** Scene. */ "Scene"] = "Scene";
@@ -15147,6 +15167,7 @@ var /** @internal */ PromiseState;
15147
15167
  this./** The number of retries after failing to load assets. */ retryCount = 1;
15148
15168
  this./** Retry delay time after failed to load assets, in milliseconds. */ retryInterval = 0;
15149
15169
  this./** The default timeout period for loading assets, in milliseconds. */ timeout = Infinity;
15170
+ this./** Base url for loading assets. */ baseUrl = null;
15150
15171
  this._loadingPromises = {};
15151
15172
  this._assetPool = Object.create(null);
15152
15173
  this._assetUrlPool = Object.create(null);
@@ -15350,6 +15371,8 @@ var /** @internal */ PromiseState;
15350
15371
  // Check url mapping
15351
15372
  var itemURL = item.url;
15352
15373
  var url = this._virtualPathMap[itemURL] ? this._virtualPathMap[itemURL] : itemURL;
15374
+ // Not absolute and base url is set
15375
+ if (!Utils.isAbsoluteUrl(url) && this.baseUrl) url = Utils.resolveAbsoluteUrl(this.baseUrl, url);
15353
15376
  // Parse url
15354
15377
  var _this__parseURL = this._parseURL(url), assetBaseURL = _this__parseURL.assetBaseURL, queryPath = _this__parseURL.queryPath;
15355
15378
  var paths = queryPath ? this._parseQueryPath(queryPath) : [];
@@ -16040,7 +16063,7 @@ SystemInfo._initialize();
16040
16063
  * Keyboard Manager.
16041
16064
  * @internal
16042
16065
  */ var KeyboardManager = /*#__PURE__*/ function() {
16043
- function KeyboardManager(engine) {
16066
+ function KeyboardManager(engine, target) {
16044
16067
  /** @internal */ this._curHeldDownKeyToIndexMap = [];
16045
16068
  /** @internal */ this._upKeyToFrameCountMap = [];
16046
16069
  /** @internal */ this._downKeyToFrameCountMap = [];
@@ -16048,17 +16071,11 @@ SystemInfo._initialize();
16048
16071
  /** @internal */ this._curFrameDownList = new DisorderedArray();
16049
16072
  /** @internal */ this._curFrameUpList = new DisorderedArray();
16050
16073
  this._nativeEvents = [];
16051
- this._hadListener = false;
16052
- // @ts-ignore
16053
- var htmlCanvas = engine._canvas._webCanvas;
16054
16074
  this._engine = engine;
16055
- this._htmlCanvas = htmlCanvas;
16056
- // Need to set tabIndex to make the canvas focus.
16057
- htmlCanvas.tabIndex = htmlCanvas.tabIndex;
16075
+ this._onBlur = this._onBlur.bind(this);
16058
16076
  this._onKeyEvent = this._onKeyEvent.bind(this);
16059
- htmlCanvas.addEventListener("keydown", this._onKeyEvent);
16060
- htmlCanvas.addEventListener("keyup", this._onKeyEvent);
16061
- this._hadListener = true;
16077
+ this._target = target;
16078
+ this._addEventListener();
16062
16079
  }
16063
16080
  var _proto = KeyboardManager.prototype;
16064
16081
  /**
@@ -16110,35 +16127,8 @@ SystemInfo._initialize();
16110
16127
  };
16111
16128
  /**
16112
16129
  * @internal
16113
- */ _proto._onFocus = function _onFocus() {
16114
- if (!this._hadListener) {
16115
- this._htmlCanvas.addEventListener("keydown", this._onKeyEvent);
16116
- this._htmlCanvas.addEventListener("keyup", this._onKeyEvent);
16117
- this._hadListener = true;
16118
- }
16119
- };
16120
- /**
16121
- * @internal
16122
- */ _proto._onBlur = function _onBlur() {
16123
- if (this._hadListener) {
16124
- this._htmlCanvas.removeEventListener("keydown", this._onKeyEvent);
16125
- this._htmlCanvas.removeEventListener("keyup", this._onKeyEvent);
16126
- this._curHeldDownKeyToIndexMap.length = 0;
16127
- this._curFrameHeldDownList.length = 0;
16128
- this._curFrameDownList.length = 0;
16129
- this._curFrameUpList.length = 0;
16130
- this._nativeEvents.length = 0;
16131
- this._hadListener = false;
16132
- }
16133
- };
16134
- /**
16135
- * @internal
16136
16130
  */ _proto._destroy = function _destroy() {
16137
- if (this._hadListener) {
16138
- this._htmlCanvas.removeEventListener("keydown", this._onKeyEvent);
16139
- this._htmlCanvas.removeEventListener("keyup", this._onKeyEvent);
16140
- this._hadListener = false;
16141
- }
16131
+ this._removeEventListener();
16142
16132
  this._curHeldDownKeyToIndexMap.length = 0;
16143
16133
  this._curHeldDownKeyToIndexMap = null;
16144
16134
  this._upKeyToFrameCountMap.length = 0;
@@ -16153,12 +16143,30 @@ SystemInfo._initialize();
16153
16143
  this._curFrameDownList = null;
16154
16144
  this._curFrameUpList.length = 0;
16155
16145
  this._curFrameUpList = null;
16156
- this._htmlCanvas = null;
16157
16146
  this._engine = null;
16158
16147
  };
16148
+ _proto._onBlur = function _onBlur() {
16149
+ this._curHeldDownKeyToIndexMap.length = 0;
16150
+ this._curFrameHeldDownList.length = 0;
16151
+ this._curFrameDownList.length = 0;
16152
+ this._curFrameUpList.length = 0;
16153
+ this._nativeEvents.length = 0;
16154
+ };
16159
16155
  _proto._onKeyEvent = function _onKeyEvent(evt) {
16160
16156
  this._nativeEvents.push(evt);
16161
16157
  };
16158
+ _proto._addEventListener = function _addEventListener() {
16159
+ var _this = this, target = _this._target;
16160
+ target.addEventListener("keydown", this._onKeyEvent);
16161
+ target.addEventListener("keyup", this._onKeyEvent);
16162
+ target.addEventListener("blur", this._onBlur);
16163
+ };
16164
+ _proto._removeEventListener = function _removeEventListener() {
16165
+ var _this = this, target = _this._target;
16166
+ target.removeEventListener("keydown", this._onKeyEvent);
16167
+ target.removeEventListener("keyup", this._onKeyEvent);
16168
+ target.removeEventListener("blur", this._onBlur);
16169
+ };
16162
16170
  return KeyboardManager;
16163
16171
  }();
16164
16172
 
@@ -18122,7 +18130,7 @@ __decorate([
18122
18130
  * Pointer Manager.
18123
18131
  * @internal
18124
18132
  */ var PointerManager = /*#__PURE__*/ function() {
18125
- function PointerManager(engine) {
18133
+ function PointerManager(engine, target) {
18126
18134
  /** @internal */ this._pointers = [];
18127
18135
  /** @internal */ this._multiPointerEnabled = true;
18128
18136
  /** @internal */ this._buttons = exports.PointerButton.None;
@@ -18131,16 +18139,18 @@ __decorate([
18131
18139
  /** @internal */ this._upList = new DisorderedArray();
18132
18140
  /** @internal */ this._downList = new DisorderedArray();
18133
18141
  this._nativeEvents = [];
18134
- this._hadListener = false;
18135
- // @ts-ignore
18136
- var htmlCanvas = engine._canvas._webCanvas;
18142
+ if (_instanceof(target, Window)) {
18143
+ throw "Do not set window as target because window cannot listen to pointer leave event.";
18144
+ }
18137
18145
  this._engine = engine;
18146
+ this._target = target;
18138
18147
  this._canvas = engine.canvas;
18139
- this._htmlCanvas = htmlCanvas;
18140
- this._onPointerEvent = this._onPointerEvent.bind(this);
18141
- this._onFocus();
18148
+ // @ts-ignore
18149
+ this._htmlCanvas = engine._canvas._webCanvas;
18142
18150
  // If there are no compatibility issues, navigator.maxTouchPoints should be used here
18143
18151
  this._pointerPool = new Array(11);
18152
+ this._onPointerEvent = this._onPointerEvent.bind(this);
18153
+ this._addEventListener();
18144
18154
  }
18145
18155
  var _proto = PointerManager.prototype;
18146
18156
  /**
@@ -18210,7 +18220,8 @@ __decorate([
18210
18220
  var length = events.length;
18211
18221
  if (length > 0) {
18212
18222
  for(var i1 = 0; i1 < length; i1++){
18213
- switch(events[i1].type){
18223
+ var event = events[i1];
18224
+ switch(event.type){
18214
18225
  case "pointerdown":
18215
18226
  pointer.phase = exports.PointerPhase.Down;
18216
18227
  pointer._firePointerDown(rayCastEntity);
@@ -18232,66 +18243,14 @@ __decorate([
18232
18243
  };
18233
18244
  /**
18234
18245
  * @internal
18235
- */ _proto._onFocus = function _onFocus() {
18236
- if (!this._hadListener) {
18237
- var _this = this, htmlCanvas = _this._htmlCanvas, onPointerEvent = _this._onPointerEvent;
18238
- htmlCanvas.addEventListener("pointerdown", onPointerEvent);
18239
- htmlCanvas.addEventListener("pointerup", onPointerEvent);
18240
- htmlCanvas.addEventListener("pointerleave", onPointerEvent);
18241
- htmlCanvas.addEventListener("pointermove", onPointerEvent);
18242
- htmlCanvas.addEventListener("pointercancel", onPointerEvent);
18243
- this._hadListener = true;
18244
- }
18245
- };
18246
- /**
18247
- * @internal
18248
- */ _proto._onBlur = function _onBlur() {
18249
- if (this._hadListener) {
18250
- var _this = this, htmlCanvas = _this._htmlCanvas, onPointerEvent = _this._onPointerEvent;
18251
- htmlCanvas.removeEventListener("pointerdown", onPointerEvent);
18252
- htmlCanvas.removeEventListener("pointerup", onPointerEvent);
18253
- htmlCanvas.removeEventListener("pointerleave", onPointerEvent);
18254
- htmlCanvas.removeEventListener("pointermove", onPointerEvent);
18255
- htmlCanvas.removeEventListener("pointercancel", onPointerEvent);
18256
- this._hadListener = false;
18257
- this._pointers.length = 0;
18258
- this._downList.length = 0;
18259
- this._upList.length = 0;
18260
- }
18261
- };
18262
- /**
18263
- * @internal
18264
18246
  */ _proto._destroy = function _destroy() {
18265
- // @ts-ignore
18266
- if (this._hadListener) {
18267
- var _this = this, htmlCanvas = _this._htmlCanvas, onPointerEvent = _this._onPointerEvent;
18268
- htmlCanvas.removeEventListener("pointerdown", onPointerEvent);
18269
- htmlCanvas.removeEventListener("pointerup", onPointerEvent);
18270
- htmlCanvas.removeEventListener("pointerleave", onPointerEvent);
18271
- htmlCanvas.removeEventListener("pointermove", onPointerEvent);
18272
- htmlCanvas.removeEventListener("pointercancel", onPointerEvent);
18273
- this._hadListener = false;
18274
- }
18247
+ this._removeEventListener();
18275
18248
  this._pointerPool.length = 0;
18276
- this._pointerPool = null;
18277
- this._pointers.length = 0;
18278
- this._pointers = null;
18279
- this._downList.length = 0;
18280
- this._downList = null;
18281
- this._upList.length = 0;
18282
- this._upList = null;
18283
18249
  this._nativeEvents.length = 0;
18284
- this._nativeEvents = null;
18285
- this._upMap.length = 0;
18286
- this._upMap = null;
18287
18250
  this._downMap.length = 0;
18288
- this._downMap = null;
18289
- this._htmlCanvas = null;
18290
- this._canvas = null;
18291
- this._engine = null;
18251
+ this._upMap.length = 0;
18292
18252
  };
18293
18253
  _proto._onPointerEvent = function _onPointerEvent(evt) {
18294
- evt.type === "pointerdown" && this._htmlCanvas.focus();
18295
18254
  this._nativeEvents.push(evt);
18296
18255
  };
18297
18256
  _proto._getPointerByID = function _getPointerByID(pointerId) {
@@ -18374,6 +18333,26 @@ __decorate([
18374
18333
  }
18375
18334
  return null;
18376
18335
  };
18336
+ _proto._addEventListener = function _addEventListener() {
18337
+ var _this = this, target = _this._target, onPointerEvent = _this._onPointerEvent;
18338
+ target.addEventListener("pointerdown", onPointerEvent);
18339
+ target.addEventListener("pointerup", onPointerEvent);
18340
+ target.addEventListener("pointerleave", onPointerEvent);
18341
+ target.addEventListener("pointermove", onPointerEvent);
18342
+ target.addEventListener("pointercancel", onPointerEvent);
18343
+ };
18344
+ _proto._removeEventListener = function _removeEventListener() {
18345
+ var _this = this, target = _this._target, onPointerEvent = _this._onPointerEvent;
18346
+ target.removeEventListener("pointerdown", onPointerEvent);
18347
+ target.removeEventListener("pointerup", onPointerEvent);
18348
+ target.removeEventListener("pointerleave", onPointerEvent);
18349
+ target.removeEventListener("pointermove", onPointerEvent);
18350
+ target.removeEventListener("pointercancel", onPointerEvent);
18351
+ this._nativeEvents.length = 0;
18352
+ this._pointers.length = 0;
18353
+ this._downList.length = 0;
18354
+ this._upList.length = 0;
18355
+ };
18377
18356
  return PointerManager;
18378
18357
  }();
18379
18358
  (function() {
@@ -18390,15 +18369,12 @@ __decorate([
18390
18369
  * Wheel Manager.
18391
18370
  * @internal
18392
18371
  */ var WheelManager = /*#__PURE__*/ function() {
18393
- function WheelManager(engine) {
18372
+ function WheelManager(engine, target) {
18394
18373
  /** @internal */ this._delta = new miniprogram.Vector3();
18395
18374
  this._nativeEvents = [];
18396
- // @ts-ignore
18397
- var htmlCanvas = engine._canvas._webCanvas;
18398
18375
  this._onWheelEvent = this._onWheelEvent.bind(this);
18399
- htmlCanvas.addEventListener("wheel", this._onWheelEvent);
18400
- this._canvas = htmlCanvas;
18401
- this._hadListener = true;
18376
+ this._target = target;
18377
+ this._addEventListener();
18402
18378
  }
18403
18379
  var _proto = WheelManager.prototype;
18404
18380
  /**
@@ -18419,35 +18395,24 @@ __decorate([
18419
18395
  };
18420
18396
  /**
18421
18397
  * @internal
18422
- */ _proto._onFocus = function _onFocus() {
18423
- if (!this._hadListener) {
18424
- this._canvas.addEventListener("wheel", this._onWheelEvent);
18425
- this._hadListener = true;
18426
- }
18398
+ */ _proto._addEventListener = function _addEventListener() {
18399
+ this._target.addEventListener("wheel", this._onWheelEvent);
18427
18400
  };
18428
18401
  /**
18429
18402
  * @internal
18430
- */ _proto._onBlur = function _onBlur() {
18431
- if (this._hadListener) {
18432
- this._canvas.removeEventListener("wheel", this._onWheelEvent);
18433
- this._nativeEvents.length = 0;
18434
- this._delta.set(0, 0, 0);
18435
- this._hadListener = false;
18436
- }
18403
+ */ _proto._removeEventListener = function _removeEventListener() {
18404
+ this._target.removeEventListener("wheel", this._onWheelEvent);
18405
+ this._nativeEvents.length = 0;
18406
+ this._delta.set(0, 0, 0);
18437
18407
  };
18438
18408
  /**
18439
18409
  * @internal
18440
18410
  */ _proto._destroy = function _destroy() {
18441
- if (this._hadListener) {
18442
- this._canvas.removeEventListener("wheel", this._onWheelEvent);
18443
- this._hadListener = false;
18444
- }
18411
+ this._removeEventListener();
18445
18412
  this._nativeEvents = null;
18446
- this._canvas = null;
18447
18413
  this._delta = null;
18448
18414
  };
18449
18415
  _proto._onWheelEvent = function _onWheelEvent(evt) {
18450
- evt.cancelable && evt.preventDefault();
18451
18416
  this._nativeEvents.push(evt);
18452
18417
  };
18453
18418
  return WheelManager;
@@ -18456,19 +18421,19 @@ __decorate([
18456
18421
  /**
18457
18422
  * InputManager manages device input such as mouse, touch, keyboard, etc.
18458
18423
  */ var InputManager = /*#__PURE__*/ function() {
18459
- function InputManager(engine) {
18424
+ function InputManager(engine, inputOptions) {
18460
18425
  /** Sometimes the input module will not be initialized, such as off-screen rendering. */ this._initialized = false;
18461
18426
  this._engine = engine;
18462
18427
  // @ts-ignore
18463
18428
  var canvas = engine._canvas._webCanvas;
18464
18429
  if (typeof engineMiniprogramAdapter.OffscreenCanvas === "undefined" || !_instanceof(canvas, engineMiniprogramAdapter.OffscreenCanvas)) {
18465
- this._wheelManager = new WheelManager(engine);
18466
- this._pointerManager = new PointerManager(engine);
18467
- this._keyboardManager = new KeyboardManager(engine);
18468
- this._onBlur = this._onBlur.bind(this);
18469
- engineMiniprogramAdapter.window.addEventListener("blur", this._onBlur);
18470
- this._onFocus = this._onFocus.bind(this);
18471
- engineMiniprogramAdapter.window.addEventListener("focus", this._onFocus);
18430
+ var _inputOptions, _inputOptions1, _inputOptions2;
18431
+ var _inputOptions_wheelTarget;
18432
+ this._wheelManager = new WheelManager(engine, (_inputOptions_wheelTarget = (_inputOptions = inputOptions) == null ? void 0 : _inputOptions.wheelTarget) != null ? _inputOptions_wheelTarget : canvas);
18433
+ var _inputOptions_pointerTarget;
18434
+ this._pointerManager = new PointerManager(engine, (_inputOptions_pointerTarget = (_inputOptions1 = inputOptions) == null ? void 0 : _inputOptions1.pointerTarget) != null ? _inputOptions_pointerTarget : canvas);
18435
+ var _inputOptions_keyboardTarget;
18436
+ this._keyboardManager = new KeyboardManager(engine, (_inputOptions_keyboardTarget = (_inputOptions2 = inputOptions) == null ? void 0 : _inputOptions2.keyboardTarget) != null ? _inputOptions_keyboardTarget : engineMiniprogramAdapter.window);
18472
18437
  this._initialized = true;
18473
18438
  }
18474
18439
  }
@@ -18581,8 +18546,6 @@ __decorate([
18581
18546
  * @internal
18582
18547
  */ _proto._destroy = function _destroy() {
18583
18548
  if (this._initialized) {
18584
- engineMiniprogramAdapter.window.removeEventListener("blur", this._onBlur);
18585
- engineMiniprogramAdapter.window.removeEventListener("focus", this._onFocus);
18586
18549
  this._wheelManager._destroy();
18587
18550
  this._wheelManager = null;
18588
18551
  this._pointerManager._destroy();
@@ -18591,16 +18554,6 @@ __decorate([
18591
18554
  this._keyboardManager = null;
18592
18555
  }
18593
18556
  };
18594
- _proto._onBlur = function _onBlur() {
18595
- this._wheelManager._onBlur();
18596
- this._pointerManager._onBlur();
18597
- this._keyboardManager._onBlur();
18598
- };
18599
- _proto._onFocus = function _onFocus() {
18600
- this._wheelManager._onFocus();
18601
- this._pointerManager._onFocus();
18602
- this._keyboardManager._onFocus();
18603
- };
18604
18557
  _create_class(InputManager, [
18605
18558
  {
18606
18559
  key: "pointers",
@@ -18979,8 +18932,9 @@ var unlitVs = "#define GLSLIFY 1\n#include <common>\n#include <common_vert>\n#in
18979
18932
  }
18980
18933
  return;
18981
18934
  }
18935
+ ++hierarchy;
18982
18936
  for(var k1 in cacheMap){
18983
- this._recursiveDestroy(++hierarchy, cacheMap[k1]);
18937
+ this._recursiveDestroy(hierarchy, cacheMap[k1]);
18984
18938
  }
18985
18939
  };
18986
18940
  _proto._resizeCacheMapHierarchy = function _resizeCacheMapHierarchy(cacheMap, hierarchy, currentHierarchy, increaseHierarchy) {
@@ -19098,7 +19052,7 @@ ShaderPool.init();
19098
19052
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
19099
19053
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
19100
19054
  _this._textDefaultFont.isGCIgnored = true;
19101
- _this.inputManager = new InputManager(_assert_this_initialized(_this));
19055
+ _this.inputManager = new InputManager(_assert_this_initialized(_this), configuration.input);
19102
19056
  var xrDevice = configuration.xrDevice;
19103
19057
  if (xrDevice) {
19104
19058
  _this.xrManager = new XRManager();
@@ -21946,7 +21900,12 @@ var passNum = 0;
21946
21900
  if (componentA.instanceId === componentB.instanceId) {
21947
21901
  return dataA.material._priority - dataB.material._priority || componentA._distanceForSort - componentB._distanceForSort;
21948
21902
  } else {
21949
- return componentA._distanceForSort - componentB._distanceForSort;
21903
+ var distanceDiff = componentA._distanceForSort - componentB._distanceForSort;
21904
+ if (distanceDiff === 0) {
21905
+ return componentA.instanceId - componentB.instanceId;
21906
+ } else {
21907
+ return distanceDiff;
21908
+ }
21950
21909
  }
21951
21910
  };
21952
21911
  /**
@@ -21964,7 +21923,12 @@ var passNum = 0;
21964
21923
  if (componentA.instanceId === componentB.instanceId) {
21965
21924
  return dataA.material._priority - dataB.material._priority || componentB._distanceForSort - componentA._distanceForSort;
21966
21925
  } else {
21967
- return componentB._distanceForSort - componentA._distanceForSort;
21926
+ var distanceDiff = componentB._distanceForSort - componentA._distanceForSort;
21927
+ if (distanceDiff === 0) {
21928
+ return componentA.instanceId - componentB.instanceId;
21929
+ } else {
21930
+ return distanceDiff;
21931
+ }
21968
21932
  }
21969
21933
  };
21970
21934
  return RenderQueue;
@@ -23178,14 +23142,14 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23178
23142
  /** @internal */ _this._cameraIndex = -1;
23179
23143
  _this._priority = 0;
23180
23144
  _this._shaderData = new ShaderData(ShaderDataGroup.Camera);
23181
- _this._isProjMatSetting = false;
23145
+ _this._isCustomViewMatrix = false;
23146
+ _this._isCustomProjectionMatrix = false;
23182
23147
  _this._nearClipPlane = 0.1;
23183
23148
  _this._farClipPlane = 100;
23184
23149
  _this._fieldOfView = 45;
23185
23150
  _this._orthographicSize = 10;
23186
23151
  _this._isProjectionDirty = true;
23187
23152
  _this._isInvProjMatDirty = true;
23188
- _this._isFrustumProjectDirty = true;
23189
23153
  _this._customAspectRatio = undefined;
23190
23154
  _this._renderTarget = null;
23191
23155
  _this._depthBufferParams = new miniprogram.Vector4();
@@ -23197,7 +23161,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23197
23161
  _this._transform = transform;
23198
23162
  _this._isViewMatrixDirty = transform.registerWorldChangeFlag();
23199
23163
  _this._isInvViewProjDirty = transform.registerWorldChangeFlag();
23200
- _this._frustumViewChangeFlag = transform.registerWorldChangeFlag();
23164
+ _this._frustumChangeFlag = transform.registerWorldChangeFlag();
23201
23165
  _this._renderPipeline = new BasicRenderPipeline(_assert_this_initialized(_this));
23202
23166
  _this._addResourceReferCount(_this.shaderData, 1);
23203
23167
  _this._updatePixelViewport();
@@ -23209,16 +23173,22 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23209
23173
  }
23210
23174
  var _proto = Camera1.prototype;
23211
23175
  /**
23176
+ * Restore the view matrix to the world matrix of the entity.
23177
+ */ _proto.resetViewMatrix = function resetViewMatrix() {
23178
+ this._isCustomViewMatrix = false;
23179
+ this._viewMatrixChange();
23180
+ };
23181
+ /**
23212
23182
  * Restore the automatic calculation of projection matrix through fieldOfView, nearClipPlane and farClipPlane.
23213
23183
  */ _proto.resetProjectionMatrix = function resetProjectionMatrix() {
23214
- this._isProjMatSetting = false;
23215
- this._projMatChange();
23184
+ this._isCustomProjectionMatrix = false;
23185
+ this._projectionMatrixChange();
23216
23186
  };
23217
23187
  /**
23218
23188
  * Restore the automatic calculation of the aspect ratio through the viewport aspect ratio.
23219
23189
  */ _proto.resetAspectRatio = function resetAspectRatio() {
23220
23190
  this._customAspectRatio = undefined;
23221
- this._projMatChange();
23191
+ this._projectionMatrixChange();
23222
23192
  };
23223
23193
  /**
23224
23194
  * Transform a point from world space to viewport space.
@@ -23348,10 +23318,9 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23348
23318
  context.replacementShader = this._replacementShader;
23349
23319
  context.replacementTag = this._replacementSubShaderTag;
23350
23320
  // compute cull frustum.
23351
- if (this.enableFrustumCulling && (this._frustumViewChangeFlag.flag || this._isFrustumProjectDirty)) {
23321
+ if (this.enableFrustumCulling && this._frustumChangeFlag.flag) {
23352
23322
  this._frustum.calculateFromMatrix(virtualCamera.viewProjectionMatrix);
23353
- this._frustumViewChangeFlag.flag = false;
23354
- this._isFrustumProjectDirty = false;
23323
+ this._frustumChangeFlag.flag = false;
23355
23324
  }
23356
23325
  this._updateShaderData();
23357
23326
  // union scene and camera macro.
@@ -23406,7 +23375,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23406
23375
  this._renderPipeline = null;
23407
23376
  this._virtualCamera = null;
23408
23377
  this._shaderData = null;
23409
- this._frustumViewChangeFlag = null;
23378
+ this._frustumChangeFlag = null;
23410
23379
  this._transform = null;
23411
23380
  this._isViewMatrixDirty = null;
23412
23381
  this._isInvViewProjDirty = null;
@@ -23428,11 +23397,16 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23428
23397
  var viewport = this._viewport;
23429
23398
  this._pixelViewport.set(viewport.x * width, viewport.y * height, viewport.z * width, viewport.w * height);
23430
23399
  };
23431
- _proto._projMatChange = function _projMatChange() {
23432
- this._isFrustumProjectDirty = true;
23400
+ _proto._viewMatrixChange = function _viewMatrixChange() {
23401
+ this._isViewMatrixDirty.flag = true;
23402
+ this._isInvViewProjDirty.flag = true;
23403
+ this._frustumChangeFlag.flag = true;
23404
+ };
23405
+ _proto._projectionMatrixChange = function _projectionMatrixChange() {
23433
23406
  this._isProjectionDirty = true;
23434
23407
  this._isInvProjMatDirty = true;
23435
23408
  this._isInvViewProjDirty.flag = true;
23409
+ this._frustumChangeFlag.flag = true;
23436
23410
  };
23437
23411
  _proto._innerViewportToWorldPoint = function _innerViewportToWorldPoint(x, y, z, invViewProjMat, out) {
23438
23412
  // Depth is a normalized value, 0 is nearPlane, 1 is farClipPlane.
@@ -23475,7 +23449,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23475
23449
  _proto._onPixelViewportChanged = function _onPixelViewportChanged() {
23476
23450
  this._updatePixelViewport();
23477
23451
  var _this__customAspectRatio;
23478
- (_this__customAspectRatio = this._customAspectRatio) != null ? _this__customAspectRatio : this._projMatChange();
23452
+ (_this__customAspectRatio = this._customAspectRatio) != null ? _this__customAspectRatio : this._projectionMatrixChange();
23479
23453
  };
23480
23454
  _create_class(Camera1, [
23481
23455
  {
@@ -23495,7 +23469,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23495
23469
  },
23496
23470
  set: function set(value) {
23497
23471
  this._nearClipPlane = value;
23498
- this._projMatChange();
23472
+ this._projectionMatrixChange();
23499
23473
  }
23500
23474
  },
23501
23475
  {
@@ -23507,7 +23481,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23507
23481
  },
23508
23482
  set: function set(value) {
23509
23483
  this._farClipPlane = value;
23510
- this._projMatChange();
23484
+ this._projectionMatrixChange();
23511
23485
  }
23512
23486
  },
23513
23487
  {
@@ -23519,7 +23493,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23519
23493
  },
23520
23494
  set: function set(value) {
23521
23495
  this._fieldOfView = value;
23522
- this._projMatChange();
23496
+ this._projectionMatrixChange();
23523
23497
  }
23524
23498
  },
23525
23499
  {
@@ -23534,7 +23508,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23534
23508
  },
23535
23509
  set: function set(value) {
23536
23510
  this._customAspectRatio = value;
23537
- this._projMatChange();
23511
+ this._projectionMatrixChange();
23538
23512
  }
23539
23513
  },
23540
23514
  {
@@ -23586,7 +23560,12 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23586
23560
  },
23587
23561
  set: function set(value) {
23588
23562
  this._virtualCamera.isOrthographic = value;
23589
- this._projMatChange();
23563
+ this._projectionMatrixChange();
23564
+ if (value) {
23565
+ this.shaderData.enableMacro("CAMERA_ORTHOGRAPHIC");
23566
+ } else {
23567
+ this.shaderData.disableMacro("CAMERA_ORTHOGRAPHIC");
23568
+ }
23590
23569
  }
23591
23570
  },
23592
23571
  {
@@ -23598,7 +23577,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23598
23577
  },
23599
23578
  set: function set(value) {
23600
23579
  this._orthographicSize = value;
23601
- this._projMatChange();
23580
+ this._projectionMatrixChange();
23602
23581
  }
23603
23582
  },
23604
23583
  {
@@ -23607,22 +23586,31 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23607
23586
  * View matrix.
23608
23587
  */ function get() {
23609
23588
  var viewMatrix = this._virtualCamera.viewMatrix;
23610
- if (this._isViewMatrixDirty.flag) {
23611
- this._isViewMatrixDirty.flag = false;
23612
- // Ignore scale.
23613
- var transform = this._transform;
23614
- miniprogram.Matrix.rotationTranslation(transform.worldRotationQuaternion, transform.worldPosition, viewMatrix);
23615
- viewMatrix.invert();
23616
- }
23589
+ if (!this._isViewMatrixDirty.flag || this._isCustomViewMatrix) {
23590
+ return viewMatrix;
23591
+ }
23592
+ this._isViewMatrixDirty.flag = false;
23593
+ // Ignore scale
23594
+ var transform = this._transform;
23595
+ miniprogram.Matrix.rotationTranslation(transform.worldRotationQuaternion, transform.worldPosition, viewMatrix);
23596
+ viewMatrix.invert();
23617
23597
  return viewMatrix;
23598
+ },
23599
+ set: function set(value) {
23600
+ this._virtualCamera.viewMatrix.copyFrom(value);
23601
+ this._isCustomViewMatrix = true;
23602
+ this._viewMatrixChange();
23618
23603
  }
23619
23604
  },
23620
23605
  {
23621
23606
  key: "projectionMatrix",
23622
- get: function get() {
23607
+ get: /**
23608
+ * The projection matrix is ​​calculated by the relevant parameters of the camera by default.
23609
+ * If it is manually set, the manual value will be maintained. Call resetProjectionMatrix() to restore it.
23610
+ */ function get() {
23623
23611
  var virtualCamera = this._virtualCamera;
23624
23612
  var projectionMatrix = virtualCamera.projectionMatrix;
23625
- if (!this._isProjectionDirty || this._isProjMatSetting) {
23613
+ if (!this._isProjectionDirty || this._isCustomProjectionMatrix) {
23626
23614
  return projectionMatrix;
23627
23615
  }
23628
23616
  this._isProjectionDirty = false;
@@ -23636,13 +23624,10 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
23636
23624
  }
23637
23625
  return projectionMatrix;
23638
23626
  },
23639
- set: /**
23640
- * The projection matrix is ​​calculated by the relevant parameters of the camera by default.
23641
- * If it is manually set, the manual value will be maintained. Call resetProjectionMatrix() to restore it.
23642
- */ function set(value) {
23627
+ set: function set(value) {
23643
23628
  this._virtualCamera.projectionMatrix.copyFrom(value);
23644
- this._isProjMatSetting = true;
23645
- this._projMatChange();
23629
+ this._isCustomProjectionMatrix = true;
23630
+ this._projectionMatrixChange();
23646
23631
  }
23647
23632
  },
23648
23633
  {
@@ -23703,7 +23688,7 @@ __decorate([
23703
23688
  ], exports.Camera.prototype, "_cameraIndex", void 0);
23704
23689
  __decorate([
23705
23690
  ignoreClone
23706
- ], exports.Camera.prototype, "_frustumViewChangeFlag", void 0);
23691
+ ], exports.Camera.prototype, "_frustumChangeFlag", void 0);
23707
23692
  __decorate([
23708
23693
  ignoreClone
23709
23694
  ], exports.Camera.prototype, "_transform", void 0);