@galacean/engine 1.0.0-beta.14 → 1.0.0-beta.16

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/browser.js CHANGED
@@ -4656,10 +4656,11 @@
4656
4656
  if (y === void 0) y = 0;
4657
4657
  if (width === void 0) width = 0;
4658
4658
  if (height === void 0) height = 0;
4659
- this.x = x;
4660
- this.y = y;
4661
- this.width = width;
4662
- this.height = height;
4659
+ /** @internal */ this._onValueChanged = null;
4660
+ this._x = x;
4661
+ this._y = y;
4662
+ this._width = width;
4663
+ this._height = height;
4663
4664
  };
4664
4665
  var _proto = Rect.prototype;
4665
4666
  /**
@@ -4670,10 +4671,11 @@
4670
4671
  * @param height - The height of the rectangle, measured from the y position
4671
4672
  * @returns This rectangle
4672
4673
  */ _proto.set = function set(x, y, width, height) {
4673
- this.x = x;
4674
- this.y = y;
4675
- this.width = width;
4676
- this.height = height;
4674
+ this._x = x;
4675
+ this._y = y;
4676
+ this._width = width;
4677
+ this._height = height;
4678
+ this._onValueChanged && this._onValueChanged();
4677
4679
  return this;
4678
4680
  };
4679
4681
  /**
@@ -4687,12 +4689,63 @@
4687
4689
  * @param source - The specified rect
4688
4690
  * @returns This rect
4689
4691
  */ _proto.copyFrom = function copyFrom(source) {
4690
- this.x = source.x;
4691
- this.y = source.y;
4692
- this.width = source.width;
4693
- this.height = source.height;
4692
+ this._x = source.x;
4693
+ this._y = source.y;
4694
+ this._width = source.width;
4695
+ this._height = source.height;
4696
+ this._onValueChanged && this._onValueChanged();
4694
4697
  return this;
4695
4698
  };
4699
+ _create_class$4(Rect, [
4700
+ {
4701
+ key: "x",
4702
+ get: /**
4703
+ * The x coordinate of the rectangle.
4704
+ */ function get() {
4705
+ return this._x;
4706
+ },
4707
+ set: function set(value) {
4708
+ this._x = value;
4709
+ this._onValueChanged && this._onValueChanged();
4710
+ }
4711
+ },
4712
+ {
4713
+ key: "y",
4714
+ get: /**
4715
+ * The y coordinate of the rectangle.
4716
+ */ function get() {
4717
+ return this._y;
4718
+ },
4719
+ set: function set(value) {
4720
+ this._y = value;
4721
+ this._onValueChanged && this._onValueChanged();
4722
+ }
4723
+ },
4724
+ {
4725
+ key: "width",
4726
+ get: /**
4727
+ * The width of the rectangle, measured from the x position.
4728
+ */ function get() {
4729
+ return this._width;
4730
+ },
4731
+ set: function set(value) {
4732
+ this._width = value;
4733
+ this._onValueChanged && this._onValueChanged();
4734
+ }
4735
+ },
4736
+ {
4737
+ key: "height",
4738
+ get: /**
4739
+ * The height of the rectangle, measured from the y position.
4740
+ */ function get() {
4741
+ return this._height;
4742
+ },
4743
+ set: function set(value) {
4744
+ this._height = value;
4745
+ this._onValueChanged && this._onValueChanged();
4746
+ }
4747
+ }
4748
+ ]);
4696
4749
  return Rect;
4697
4750
  }();
4698
4751
  /**
@@ -7824,15 +7877,24 @@
7824
7877
  };
7825
7878
  var _proto = DisorderedArray.prototype;
7826
7879
  _proto.add = function add(element) {
7827
- if (this.length === this._elements.length) this._elements.push(element);
7828
- else this._elements[this.length] = element;
7880
+ if (this.length === this._elements.length) {
7881
+ this._elements.push(element);
7882
+ } else {
7883
+ this._elements[this.length] = element;
7884
+ }
7829
7885
  this.length++;
7830
7886
  };
7831
7887
  _proto.delete = function _delete(element) {
7832
- //TODO: It can be optimized for custom binary search and other algorithms, currently this._elements>=this.length wastes performance.
7888
+ // @todo: It can be optimized for custom binary search and other algorithms, currently this._elements>=this.length wastes performance.
7833
7889
  var index = this._elements.indexOf(element);
7834
7890
  this.deleteByIndex(index);
7835
7891
  };
7892
+ _proto.set = function set(index, element) {
7893
+ if (index >= this.length) {
7894
+ throw "Index is out of range.";
7895
+ }
7896
+ this._elements[index] = element;
7897
+ };
7836
7898
  _proto.get = function get(index) {
7837
7899
  if (index >= this.length) {
7838
7900
  throw "Index is out of range.";
@@ -7840,9 +7902,9 @@
7840
7902
  return this._elements[index];
7841
7903
  };
7842
7904
  /**
7843
- *
7844
- * @param index
7845
- * @returns The replaced item is used to reset its index.
7905
+ * Delete the element at the specified index.
7906
+ * @param index - The index of the element to be deleted
7907
+ * @returns The replaced item is used to reset its index
7846
7908
  */ _proto.deleteByIndex = function deleteByIndex(index) {
7847
7909
  var elements = this._elements;
7848
7910
  var end = null;
@@ -13154,31 +13216,18 @@
13154
13216
  };
13155
13217
  /**
13156
13218
  * @internal
13157
- */ _proto._getSunLightIndex = function _getSunLightIndex() {
13219
+ */ _proto._updateSunLightIndex = function _updateSunLightIndex() {
13158
13220
  var directLights = this._directLights;
13159
- var sunLightIndex = -1;
13160
- var maxIntensity = Number.NEGATIVE_INFINITY;
13161
- var hasShadowLight = false;
13162
- for(var i = 0, n = directLights.length; i < n; i++){
13163
- var directLight = directLights.get(i);
13164
- if (directLight.shadowType !== exports.ShadowType.None && !hasShadowLight) {
13165
- maxIntensity = Number.NEGATIVE_INFINITY;
13166
- hasShadowLight = true;
13167
- }
13168
- var intensity = directLight.intensity * directLight.color.getBrightness();
13169
- if (hasShadowLight) {
13170
- if (directLight.shadowType !== exports.ShadowType.None && maxIntensity < intensity) {
13171
- maxIntensity = intensity;
13172
- sunLightIndex = i;
13173
- }
13174
- } else {
13175
- if (maxIntensity < intensity) {
13176
- maxIntensity = intensity;
13177
- sunLightIndex = i;
13178
- }
13179
- }
13221
+ var index = this._getSunLightIndex();
13222
+ // -1 means no sun light, 0 means the first direct light already is sun light
13223
+ if (index > 0) {
13224
+ var firstLight = directLights.get(0);
13225
+ var sunLight = directLights.get(index);
13226
+ directLights.set(0, sunLight);
13227
+ directLights.set(index, firstLight);
13228
+ sunLight._lightIndex = 0;
13229
+ firstLight._lightIndex = index;
13180
13230
  }
13181
- return sunLightIndex;
13182
13231
  };
13183
13232
  /**
13184
13233
  * @internal
@@ -13227,6 +13276,32 @@
13227
13276
  this._pointLights.garbageCollection();
13228
13277
  this._directLights.garbageCollection();
13229
13278
  };
13279
+ _proto._getSunLightIndex = function _getSunLightIndex() {
13280
+ var directLights = this._directLights;
13281
+ var sunLightIndex = -1;
13282
+ var maxIntensity = Number.NEGATIVE_INFINITY;
13283
+ var hasShadowLight = false;
13284
+ for(var i = 0, n = directLights.length; i < n; i++){
13285
+ var directLight = directLights.get(i);
13286
+ if (directLight.shadowType !== exports.ShadowType.None && !hasShadowLight) {
13287
+ maxIntensity = Number.NEGATIVE_INFINITY;
13288
+ hasShadowLight = true;
13289
+ }
13290
+ var intensity = directLight.intensity * directLight.color.getBrightness();
13291
+ if (hasShadowLight) {
13292
+ if (directLight.shadowType !== exports.ShadowType.None && maxIntensity < intensity) {
13293
+ maxIntensity = intensity;
13294
+ sunLightIndex = i;
13295
+ }
13296
+ } else {
13297
+ if (maxIntensity < intensity) {
13298
+ maxIntensity = intensity;
13299
+ sunLightIndex = i;
13300
+ }
13301
+ }
13302
+ }
13303
+ return sunLightIndex;
13304
+ };
13230
13305
  return LightManager;
13231
13306
  }();
13232
13307
  /**
@@ -14226,6 +14301,7 @@
14226
14301
  /**
14227
14302
  * @override
14228
14303
  */ _proto._onDestroy = function _onDestroy() {
14304
+ ReferResource.prototype._onDestroy.call(this);
14229
14305
  this._shader = null;
14230
14306
  this._shaderData = null;
14231
14307
  this._renderStates.length = 0;
@@ -14382,7 +14458,7 @@
14382
14458
  var mobile_material_frag = "#define GLSLIFY 1\nuniform vec4 material_EmissiveColor;uniform vec4 material_BaseColor;uniform vec4 material_SpecularColor;uniform float material_Shininess;uniform float material_NormalIntensity;uniform float material_AlphaCutoff;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nuniform sampler2D material_EmissiveTexture;\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nuniform sampler2D material_BaseTexture;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\nuniform sampler2D material_SpecularTexture;\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nuniform sampler2D material_NormalTexture;\n#endif\n"; // eslint-disable-line
14383
14459
  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
14384
14460
  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
14385
- 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();int sunIndex=int(scene_ShadowInfo.z);\n#endif\nDirectLight directionalLight;for(int i=0;i<SCENE_DIRECT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_DirectLightCullingMask[i]))continue;directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==sunIndex){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];float d=max(dot(N,-directionalLight.direction),0.0);lightDiffuse+=directionalLight.color*d;vec3 halfDir=normalize(V-directionalLight.direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess);lightSpecular+=directionalLight.color*s;}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i]))continue;pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];vec3 direction=v_pos-pointLight.position;float dist=length(direction);direction/=dist;float decay=clamp(1.0-pow(dist/pointLight.distance,4.0),0.0,1.0);float d=max(dot(N,-direction),0.0)*decay;lightDiffuse+=pointLight.color*d;vec3 halfDir=normalize(V-direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decay;lightSpecular+=pointLight.color*s;}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nSpotLight spotLight;for(int i=0;i<SCENE_SPOT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_SpotLightCullingMask[i]))continue;spotLight.color=scene_SpotLightColor[i];spotLight.position=scene_SpotLightPosition[i];spotLight.direction=scene_SpotLightDirection[i];spotLight.distance=scene_SpotLightDistance[i];spotLight.angleCos=scene_SpotLightAngleCos[i];spotLight.penumbraCos=scene_SpotLightPenumbraCos[i];vec3 direction=spotLight.position-v_pos;float lightDistance=length(direction);direction/=lightDistance;float angleCos=dot(direction,-spotLight.direction);float decay=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayTotal=decay*spotEffect;float d=max(dot(N,direction),0.0)*decayTotal;lightDiffuse+=spotLight.color*d;vec3 halfDir=normalize(V+direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decayTotal;lightSpecular+=spotLight.color*s;}\n#endif\ndiffuse*=vec4(lightDiffuse,1.0);specular*=vec4(lightSpecular,1.0);\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(diffuse.a<material_AlphaCutoff){discard;}\n#endif\n"; // eslint-disable-line
14461
+ var mobile_blinnphong_frag = "#define GLSLIFY 1\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nmat3 tbn=getTBN(gl_FrontFacing);vec3 N=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,gl_FrontFacing);\n#else\nvec3 N=getNormal(gl_FrontFacing);\n#endif\nvec3 lightDiffuse=vec3(0.0,0.0,0.0);vec3 lightSpecular=vec3(0.0,0.0,0.0);float shadowAttenuation=1.0;\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nshadowAttenuation=1.0;\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nshadowAttenuation*=sampleShadowMap();\n#endif\nDirectLight directionalLight;for(int i=0;i<SCENE_DIRECT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_DirectLightCullingMask[i]))continue;directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==0){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];float d=max(dot(N,-directionalLight.direction),0.0);lightDiffuse+=directionalLight.color*d;vec3 halfDir=normalize(V-directionalLight.direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess);lightSpecular+=directionalLight.color*s;}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i]))continue;pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];vec3 direction=v_pos-pointLight.position;float dist=length(direction);direction/=dist;float decay=clamp(1.0-pow(dist/pointLight.distance,4.0),0.0,1.0);float d=max(dot(N,-direction),0.0)*decay;lightDiffuse+=pointLight.color*d;vec3 halfDir=normalize(V-direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decay;lightSpecular+=pointLight.color*s;}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nSpotLight spotLight;for(int i=0;i<SCENE_SPOT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_SpotLightCullingMask[i]))continue;spotLight.color=scene_SpotLightColor[i];spotLight.position=scene_SpotLightPosition[i];spotLight.direction=scene_SpotLightDirection[i];spotLight.distance=scene_SpotLightDistance[i];spotLight.angleCos=scene_SpotLightAngleCos[i];spotLight.penumbraCos=scene_SpotLightPenumbraCos[i];vec3 direction=spotLight.position-v_pos;float lightDistance=length(direction);direction/=lightDistance;float angleCos=dot(direction,-spotLight.direction);float decay=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayTotal=decay*spotEffect;float d=max(dot(N,direction),0.0)*decayTotal;lightDiffuse+=spotLight.color*d;vec3 halfDir=normalize(V+direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decayTotal;lightSpecular+=spotLight.color*s;}\n#endif\ndiffuse*=vec4(lightDiffuse,1.0);specular*=vec4(lightSpecular,1.0);\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(diffuse.a<material_AlphaCutoff){discard;}\n#endif\n"; // eslint-disable-line
14386
14462
  var noise_cellular = "#define GLSLIFY 1\n#include <noise_cellular_2D>\n#include <noise_cellular_3D>\n#include <noise_cellular_2x2>\n#include <noise_cellular_2x2x2>\n"; // eslint-disable-line
14387
14463
  var noise_cellular_2D = "#define GLSLIFY 1\nvec2 cellular(vec2 P){vec2 Pi=mod289(floor(P));vec2 Pf=fract(P);vec3 oi=vec3(-1.0,0.0,1.0);vec3 of=vec3(-0.5,0.5,1.5);vec3 px=permute(Pi.x+oi);vec3 p=permute(px.x+Pi.y+oi);vec3 ox=fract(p*K)-Ko;vec3 oy=mod7(floor(p*K))*K-Ko;vec3 dx=Pf.x+0.5+jitter*ox;vec3 dy=Pf.y-of+jitter*oy;vec3 d1=dx*dx+dy*dy;p=permute(px.y+Pi.y+oi);ox=fract(p*K)-Ko;oy=mod7(floor(p*K))*K-Ko;dx=Pf.x-0.5+jitter*ox;dy=Pf.y-of+jitter*oy;vec3 d2=dx*dx+dy*dy;p=permute(px.z+Pi.y+oi);ox=fract(p*K)-Ko;oy=mod7(floor(p*K))*K-Ko;dx=Pf.x-1.5+jitter*ox;dy=Pf.y-of+jitter*oy;vec3 d3=dx*dx+dy*dy;vec3 d1a=min(d1,d2);d2=max(d1,d2);d2=min(d2,d3);d1=min(d1a,d2);d2=max(d1a,d2);d1.xy=(d1.x<d1.y)? d1.xy : d1.yx;d1.xz=(d1.x<d1.z)? d1.xz : d1.zx;d1.yz=min(d1.yz,d2.yz);d1.y=min(d1.y,d1.z);d1.y=min(d1.y,d2.x);return sqrt(d1.xy);}"; // eslint-disable-line
14388
14464
  var noise_cellular_2x2 = "#define GLSLIFY 1\nvec2 cellular2x2(vec2 P){vec2 Pi=mod289(floor(P));vec2 Pf=fract(P);vec4 Pfx=Pf.x+vec4(-0.5,-1.5,-0.5,-1.5);vec4 Pfy=Pf.y+vec4(-0.5,-0.5,-1.5,-1.5);vec4 p=permute(Pi.x+vec4(0.0,1.0,0.0,1.0));p=permute(p+Pi.y+vec4(0.0,0.0,1.0,1.0));vec4 ox=mod7(p)*K+Kd2;vec4 oy=mod7(floor(p*K))*K+Kd2;vec4 dx=Pfx+jitter1*ox;vec4 dy=Pfy+jitter1*oy;vec4 d=dx*dx+dy*dy;d.xy=(d.x<d.y)? d.xy : d.yx;d.xz=(d.x<d.z)? d.xz : d.zx;d.xw=(d.x<d.w)? d.xw : d.wx;d.y=min(d.y,d.z);d.y=min(d.y,d.w);return sqrt(d.xy);}"; // eslint-disable-line
@@ -14402,7 +14478,7 @@
14402
14478
  var pbr_frag_define = "#define GLSLIFY 1\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;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nuniform float material_ClearCoat;uniform float material_ClearCoatRoughness;\n#endif\nuniform float material_NormalIntensity;uniform float material_OcclusionIntensity;uniform float material_OcclusionTextureCoord;\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\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\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};struct Material{vec3 diffuseColor;float roughness;vec3 specularColor;float opacity;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoat;float clearCoatRoughness;\n#endif\n};"; // eslint-disable-line
14403
14479
  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 0.04+max(max(dxy.x,dxy.y),dxy.z);\n#else\nreturn 0.04;\n#endif\n}void 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)\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}void initMaterial(out Material material,const in 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));\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}\n#include <brdf>\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n"; // eslint-disable-line
14404
14480
  var brdf = "#define GLSLIFY 1\nfloat F_Schlick(float dotLH){return 0.04+0.96*(pow(1.0-dotLH,5.0));}vec3 F_Schlick(vec3 specularColor,float dotLH){float fresnel=exp2((-5.55473*dotLH-6.98316)*dotLH);return(1.0-specularColor)*fresnel+specularColor;}float G_GGX_SmithCorrelated(float alpha,float dotNL,float dotNV){float a2=pow2(alpha);float gv=dotNL*sqrt(a2+(1.0-a2)*pow2(dotNV));float gl=dotNV*sqrt(a2+(1.0-a2)*pow2(dotNL));return 0.5/max(gv+gl,EPSILON);}float D_GGX(float alpha,float dotNH){float a2=pow2(alpha);float denom=pow2(dotNH)*(a2-1.0)+1.0;return RECIPROCAL_PI*a2/pow2(denom);}vec3 BRDF_Specular_GGX(vec3 incidentDirection,vec3 viewDir,vec3 normal,vec3 specularColor,float roughness){float alpha=pow2(roughness);vec3 halfDir=normalize(incidentDirection+viewDir);float dotNL=saturate(dot(normal,incidentDirection));float dotNV=saturate(dot(normal,viewDir));float dotNH=saturate(dot(normal,halfDir));float dotLH=saturate(dot(incidentDirection,halfDir));vec3 F=F_Schlick(specularColor,dotLH);float G=G_GGX_SmithCorrelated(alpha,dotNL,dotNV);float D=D_GGX(alpha,dotNH);return F*(G*D);}vec3 BRDF_Diffuse_Lambert(vec3 diffuseColor){return RECIPROCAL_PI*diffuseColor;}"; // eslint-disable-line
14405
- var direct_irradiance_frag_define = "#define GLSLIFY 1\n#include <ShadowFragmentDeclaration>\nvoid addDirectRadiance(vec3 incidentDirection,vec3 color,Geometry geometry,Material material,inout ReflectedLight reflectedLight){float attenuation=1.0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoatDotNL=saturate(dot(geometry.clearCoatNormal,incidentDirection));vec3 clearCoatIrradiance=clearCoatDotNL*color;reflectedLight.directSpecular+=material.clearCoat*clearCoatIrradiance*BRDF_Specular_GGX(incidentDirection,geometry.viewDir,geometry.clearCoatNormal,vec3(0.04),material.clearCoatRoughness);attenuation-=material.clearCoat*F_Schlick(geometry.clearCoatDotNV);\n#endif\nfloat dotNL=saturate(dot(geometry.normal,incidentDirection));vec3 irradiance=dotNL*color*PI;reflectedLight.directSpecular+=attenuation*irradiance*BRDF_Specular_GGX(incidentDirection,geometry.viewDir,geometry.normal,material.specularColor,material.roughness);reflectedLight.directDiffuse+=attenuation*irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);}\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nvoid addDirectionalDirectLightRadiance(DirectLight directionalLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 color=directionalLight.color;vec3 direction=-directionalLight.direction;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nvoid addPointDirectLightRadiance(PointLight pointLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=pointLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);vec3 color=pointLight.color;color*=clamp(1.0-pow(lightDistance/pointLight.distance,4.0),0.0,1.0);addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nvoid addSpotDirectLightRadiance(SpotLight spotLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=spotLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);float angleCos=dot(direction,-spotLight.direction);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayEffect=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);vec3 color=spotLight.color;color*=spotEffect*decayEffect;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\nvoid addTotalDirectRadiance(Geometry geometry,Material material,inout ReflectedLight reflectedLight){float shadowAttenuation=1.0;\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nshadowAttenuation=1.0;\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nshadowAttenuation*=sampleShadowMap();int sunIndex=int(scene_ShadowInfo.z);\n#endif\nDirectLight directionalLight;for(int i=0;i<SCENE_DIRECT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_DirectLightCullingMask[i]))continue;directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==sunIndex){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];addDirectionalDirectLightRadiance(directionalLight,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i]))continue;pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];addPointDirectLightRadiance(pointLight,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nSpotLight spotLight;for(int i=0;i<SCENE_SPOT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_SpotLightCullingMask[i]))continue;spotLight.color=scene_SpotLightColor[i];spotLight.position=scene_SpotLightPosition[i];spotLight.direction=scene_SpotLightDirection[i];spotLight.distance=scene_SpotLightDistance[i];spotLight.angleCos=scene_SpotLightAngleCos[i];spotLight.penumbraCos=scene_SpotLightPenumbraCos[i];addSpotDirectLightRadiance(spotLight,geometry,material,reflectedLight);}\n#endif\n}"; // eslint-disable-line
14481
+ var direct_irradiance_frag_define = "#define GLSLIFY 1\n#include <ShadowFragmentDeclaration>\nvoid addDirectRadiance(vec3 incidentDirection,vec3 color,Geometry geometry,Material material,inout ReflectedLight reflectedLight){float attenuation=1.0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoatDotNL=saturate(dot(geometry.clearCoatNormal,incidentDirection));vec3 clearCoatIrradiance=clearCoatDotNL*color;reflectedLight.directSpecular+=material.clearCoat*clearCoatIrradiance*BRDF_Specular_GGX(incidentDirection,geometry.viewDir,geometry.clearCoatNormal,vec3(0.04),material.clearCoatRoughness);attenuation-=material.clearCoat*F_Schlick(geometry.clearCoatDotNV);\n#endif\nfloat dotNL=saturate(dot(geometry.normal,incidentDirection));vec3 irradiance=dotNL*color*PI;reflectedLight.directSpecular+=attenuation*irradiance*BRDF_Specular_GGX(incidentDirection,geometry.viewDir,geometry.normal,material.specularColor,material.roughness);reflectedLight.directDiffuse+=attenuation*irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);}\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nvoid addDirectionalDirectLightRadiance(DirectLight directionalLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 color=directionalLight.color;vec3 direction=-directionalLight.direction;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nvoid addPointDirectLightRadiance(PointLight pointLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=pointLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);vec3 color=pointLight.color;color*=clamp(1.0-pow(lightDistance/pointLight.distance,4.0),0.0,1.0);addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nvoid addSpotDirectLightRadiance(SpotLight spotLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=spotLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);float angleCos=dot(direction,-spotLight.direction);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayEffect=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);vec3 color=spotLight.color;color*=spotEffect*decayEffect;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\nvoid addTotalDirectRadiance(Geometry geometry,Material material,inout ReflectedLight reflectedLight){float shadowAttenuation=1.0;\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nshadowAttenuation=1.0;\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nshadowAttenuation*=sampleShadowMap();\n#endif\nDirectLight directionalLight;for(int i=0;i<SCENE_DIRECT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_DirectLightCullingMask[i]))continue;directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==0){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];addDirectionalDirectLightRadiance(directionalLight,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i]))continue;pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];addPointDirectLightRadiance(pointLight,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nSpotLight spotLight;for(int i=0;i<SCENE_SPOT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_SpotLightCullingMask[i]))continue;spotLight.color=scene_SpotLightColor[i];spotLight.position=scene_SpotLightPosition[i];spotLight.direction=scene_SpotLightDirection[i];spotLight.distance=scene_SpotLightDistance[i];spotLight.angleCos=scene_SpotLightAngleCos[i];spotLight.penumbraCos=scene_SpotLightPenumbraCos[i];addSpotDirectLightRadiance(spotLight,geometry,material,reflectedLight);}\n#endif\n}"; // eslint-disable-line
14406
14482
  var ibl_frag_define = "#define GLSLIFY 1\nvec3 getLightProbeIrradiance(vec3 sh[9],vec3 normal){normal.x=-normal.x;vec3 result=sh[0]+sh[1]*(normal.y)+sh[2]*(normal.z)+sh[3]*(normal.x)+sh[4]*(normal.y*normal.x)+sh[5]*(normal.y*normal.z)+sh[6]*(3.0*normal.z*normal.z-1.0)+sh[7]*(normal.z*normal.x)+sh[8]*(normal.x*normal.x-normal.y*normal.y);return max(result,vec3(0.0));}vec3 envBRDFApprox(vec3 specularColor,float roughness,float dotNV){const vec4 c0=vec4(-1,-0.0275,-0.572,0.022);const vec4 c1=vec4(1,0.0425,1.04,-0.04);vec4 r=roughness*c0+c1;float a004=min(r.x*r.x,exp2(-9.28*dotNV))*r.x+r.y;vec2 AB=vec2(-1.04,1.04)*a004+r.zw;return specularColor*AB.x+AB.y;}float getSpecularMIPLevel(float roughness,int maxMIPLevel){return roughness*float(maxMIPLevel);}vec3 getLightProbeRadiance(vec3 viewDir,vec3 normal,float roughness,int maxMIPLevel,float specularIntensity){\n#ifndef SCENE_USE_SPECULAR_ENV\nreturn vec3(0);\n#else\nvec3 reflectVec=reflect(-viewDir,normal);reflectVec.x=-reflectVec.x;float specularMIPLevel=getSpecularMIPLevel(roughness,maxMIPLevel);\n#ifdef HAS_TEX_LOD\nvec4 envMapColor=textureCubeLodEXT(scene_EnvSpecularSampler,reflectVec,specularMIPLevel);\n#else\nvec4 envMapColor=textureCube(scene_EnvSpecularSampler,reflectVec,specularMIPLevel);\n#endif\n#ifdef SCENE_IS_DECODE_ENV_RGBM\nenvMapColor.rgb=RGBMToLinear(envMapColor,5.0).rgb;\n#ifdef ENGINE_IS_COLORSPACE_GAMMA\nenvMapColor=linearToGamma(envMapColor);\n#endif\n#else\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nenvMapColor=gammaToLinear(envMapColor);\n#endif\n#endif\nreturn envMapColor.rgb*specularIntensity;\n#endif\n}"; // eslint-disable-line
14407
14483
  var pbr_frag = "#define GLSLIFY 1\nGeometry geometry;Material material;ReflectedLight reflectedLight=ReflectedLight(vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0));initGeometry(geometry,gl_FrontFacing);initMaterial(material,geometry);addTotalDirectRadiance(geometry,material,reflectedLight);\n#ifdef SCENE_USE_SH\nvec3 irradiance=getLightProbeIrradiance(scene_EnvSH,geometry.normal);\n#ifdef ENGINE_IS_COLORSPACE_GAMMA\nirradiance=linearToGamma(vec4(irradiance,1.0)).rgb;\n#endif\nirradiance*=scene_EnvMapLight.diffuseIntensity;\n#else\nvec3 irradiance=scene_EnvMapLight.diffuse*scene_EnvMapLight.diffuseIntensity;irradiance*=PI;\n#endif\nreflectedLight.indirectDiffuse+=irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);vec3 radiance=getLightProbeRadiance(geometry.viewDir,geometry.normal,material.roughness,int(scene_EnvMapLight.mipMapLevel),scene_EnvMapLight.specularIntensity);float radianceAttenuation=1.0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nvec3 clearCoatRadiance=getLightProbeRadiance(geometry.viewDir,geometry.clearCoatNormal,material.clearCoatRoughness,int(scene_EnvMapLight.mipMapLevel),scene_EnvMapLight.specularIntensity);reflectedLight.indirectSpecular+=clearCoatRadiance*material.clearCoat*envBRDFApprox(vec3(0.04),material.clearCoatRoughness,geometry.clearCoatDotNV);radianceAttenuation-=material.clearCoat*F_Schlick(geometry.clearCoatDotNV);\n#endif\nreflectedLight.indirectSpecular+=radianceAttenuation*radiance*envBRDFApprox(material.specularColor,material.roughness,geometry.dotNV);\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\nvec2 aoUV=v_uv;\n#ifdef RENDERER_HAS_UV1\nif(material_OcclusionTextureCoord==1.0){aoUV=v_uv1;}\n#endif\nfloat ambientOcclusion=(texture2D(material_OcclusionTexture,aoUV).r-1.0)*material_OcclusionIntensity+1.0;reflectedLight.indirectDiffuse*=ambientOcclusion;\n#ifdef SCENE_USE_SPECULAR_ENV\nreflectedLight.indirectSpecular*=computeSpecularOcclusion(ambientOcclusion,material.roughness,geometry.dotNV);\n#endif\n#endif\nvec3 emissiveRadiance=material_EmissiveColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nvec4 emissiveColor=texture2D(material_EmissiveTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nemissiveColor=gammaToLinear(emissiveColor);\n#endif\nemissiveRadiance*=emissiveColor.rgb;\n#endif\nvec3 totalRadiance=reflectedLight.directDiffuse+reflectedLight.indirectDiffuse+reflectedLight.directSpecular+reflectedLight.indirectSpecular+emissiveRadiance;vec4 targetColor=vec4(totalRadiance,material.opacity);gl_FragColor=targetColor;"; // eslint-disable-line
14408
14484
  var PBRShaderLib = {
@@ -20075,10 +20151,10 @@
20075
20151
  var vertexElements = [];
20076
20152
  var vertexStride = this.createVertexElements(vertexElements);
20077
20153
  // vertices
20078
- var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
20154
+ var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * vertexStride, exports.BufferUsage.Dynamic);
20079
20155
  vertexBuffer.isGCIgnored = true;
20080
20156
  // indices
20081
- var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
20157
+ var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 6, exports.BufferUsage.Dynamic);
20082
20158
  indiceBuffer.isGCIgnored = true;
20083
20159
  mesh.setVertexBufferBinding(vertexBuffer, vertexStride);
20084
20160
  mesh.setIndexBufferBinding(indiceBuffer, exports.IndexFormat.UInt16);
@@ -20616,20 +20692,25 @@
20616
20692
  })(exports.DiffuseMode || (exports.DiffuseMode = {}));
20617
20693
  /**
20618
20694
  * Ambient light.
20619
- */ var AmbientLight = /*#__PURE__*/ function() {
20620
- var AmbientLight = function AmbientLight() {
20621
- this._diffuseSolidColor = new Color$1(0.212, 0.227, 0.259);
20622
- this._diffuseIntensity = 1.0;
20623
- this._specularIntensity = 1.0;
20624
- this._diffuseMode = exports.DiffuseMode.SolidColor;
20625
- this._shArray = new Float32Array(27);
20626
- this._scenes = [];
20627
- this._specularTextureDecodeRGBM = false;
20695
+ */ var AmbientLight = /*#__PURE__*/ function(ReferResource) {
20696
+ var AmbientLight = function AmbientLight(engine) {
20697
+ var _this;
20698
+ _this = ReferResource.call(this, engine) || this;
20699
+ _this._diffuseSolidColor = new Color$1(0.212, 0.227, 0.259);
20700
+ _this._diffuseIntensity = 1.0;
20701
+ _this._specularIntensity = 1.0;
20702
+ _this._diffuseMode = exports.DiffuseMode.SolidColor;
20703
+ _this._shArray = new Float32Array(27);
20704
+ _this._scenes = [];
20705
+ _this._specularTextureDecodeRGBM = false;
20706
+ return _this;
20628
20707
  };
20708
+ _inherits$2(AmbientLight, ReferResource);
20629
20709
  var _proto = AmbientLight.prototype;
20630
20710
  /**
20631
20711
  * @internal
20632
20712
  */ _proto._addToScene = function _addToScene(scene) {
20713
+ this._addReferCount(1);
20633
20714
  this._scenes.push(scene);
20634
20715
  var shaderData = scene.shaderData;
20635
20716
  shaderData.setColor(AmbientLight._diffuseColorProperty, this._diffuseSolidColor);
@@ -20643,9 +20724,13 @@
20643
20724
  /**
20644
20725
  * @internal
20645
20726
  */ _proto._removeFromScene = function _removeFromScene(scene) {
20727
+ this._addReferCount(-1);
20646
20728
  var scenes = this._scenes;
20647
20729
  var index = scenes.indexOf(scene);
20648
20730
  scenes.splice(index, 1);
20731
+ var shaderData = scene.shaderData;
20732
+ shaderData.setTexture(AmbientLight._specularTextureProperty, null);
20733
+ shaderData.disableMacro(AmbientLight._specularMacro);
20649
20734
  };
20650
20735
  _proto._setDiffuseMode = function _setDiffuseMode(sceneShaderData) {
20651
20736
  if (this._diffuseMode === exports.DiffuseMode.SphericalHarmonics) {
@@ -20833,7 +20918,7 @@
20833
20918
  }
20834
20919
  ]);
20835
20920
  return AmbientLight;
20836
- }();
20921
+ }(ReferResource);
20837
20922
  (function() {
20838
20923
  AmbientLight._shMacro = ShaderMacro.getByName("SCENE_USE_SH");
20839
20924
  })();
@@ -20889,7 +20974,7 @@
20889
20974
  _this.name = name || "";
20890
20975
  var shaderData = _this.shaderData;
20891
20976
  shaderData._addReferCount(1);
20892
- _this.ambientLight = new AmbientLight();
20977
+ _this.ambientLight = new AmbientLight(engine);
20893
20978
  engine.sceneManager._allScenes.push(_assert_this_initialized(_this));
20894
20979
  shaderData.enableMacro("SCENE_FOG_MODE", _this._fogMode.toString());
20895
20980
  shaderData.enableMacro("SCENE_SHADOW_CASCADED_COUNT", _this.shadowCascades.toString());
@@ -20997,6 +21082,7 @@
20997
21082
  if (this._destroyed) {
20998
21083
  return;
20999
21084
  }
21085
+ EngineObject.prototype.destroy.call(this);
21000
21086
  this._destroy();
21001
21087
  var allScenes = this.engine.sceneManager._allScenes;
21002
21088
  allScenes.splice(allScenes.indexOf(this), 1);
@@ -21039,9 +21125,9 @@
21039
21125
  var lightManager = engine._lightManager;
21040
21126
  engine.time._updateSceneShaderData(shaderData);
21041
21127
  lightManager._updateShaderData(this.shaderData);
21042
- var sunLightIndex = lightManager._getSunLightIndex();
21043
- if (sunLightIndex !== -1) {
21044
- var sunlight = lightManager._directLights.get(sunLightIndex);
21128
+ lightManager._updateSunLightIndex();
21129
+ if (lightManager._directLights.length > 0) {
21130
+ var sunlight = lightManager._directLights.get(0);
21045
21131
  shaderData.setColor(Scene._sunlightColorProperty, sunlight._getLightIntensityColor());
21046
21132
  shaderData.setVector3(Scene._sunlightDirectionProperty, sunlight.direction);
21047
21133
  this._sunLight = sunlight;
@@ -21076,6 +21162,7 @@
21076
21162
  }
21077
21163
  this._activeCameras.length = 0;
21078
21164
  this.background.destroy();
21165
+ this._ambientLight && this._ambientLight._removeFromScene(this);
21079
21166
  this.shaderData._addReferCount(-1);
21080
21167
  };
21081
21168
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -21302,10 +21389,9 @@
21302
21389
  * @internal
21303
21390
  */ _proto._destroyAllScene = function _destroyAllScene() {
21304
21391
  var allScenes = this._allScenes;
21305
- for(var i = 0, n = allScenes.length; i < n; i++){
21306
- allScenes[i]._destroy();
21392
+ while(allScenes[0]){
21393
+ allScenes[0].destroy();
21307
21394
  }
21308
- allScenes.length = 0;
21309
21395
  };
21310
21396
  _create_class$3(SceneManager, [
21311
21397
  {
@@ -23047,9 +23133,8 @@
23047
23133
  var lightUp = this._lightUp;
23048
23134
  var lightSide = this._lightSide;
23049
23135
  var lightForward = shadowSliceData.virtualCamera.forward;
23050
- var sunLightIndex = engine._lightManager._getSunLightIndex();
23051
- if (sunLightIndex !== -1) {
23052
- var light = camera.scene._sunLight;
23136
+ var light = camera.scene._sunLight;
23137
+ if (light) {
23053
23138
  var shadowFar = Math.min(camera.scene.shadowDistance, camera.farClipPlane);
23054
23139
  this._getCascadesSplitDistance(shadowFar);
23055
23140
  // prepare render target
@@ -23062,7 +23147,7 @@
23062
23147
  rhi.clearRenderTarget(engine, exports.CameraClearFlags.All, CascadedShadowCasterPass._clearColor);
23063
23148
  }
23064
23149
  this._shadowInfos.x = light.shadowStrength;
23065
- this._shadowInfos.z = sunLightIndex;
23150
+ this._shadowInfos.z = 0; // @todo: sun light index always 0
23066
23151
  // prepare light and camera direction
23067
23152
  Matrix.rotationQuaternion(light.entity.transform.worldRotationQuaternion, lightWorld);
23068
23153
  lightSide.set(lightWorldE[0], lightWorldE[1], lightWorldE[2]);
@@ -25375,6 +25460,15 @@
25375
25460
  _this._dirtyUpdateFlag = 0x7;
25376
25461
  /** @internal */ _this._updateFlagManager = new UpdateFlagManager();
25377
25462
  _this._texture = texture;
25463
+ _this._onRegionChange = _this._onRegionChange.bind(_assert_this_initialized(_this));
25464
+ _this._onPivotChange = _this._onPivotChange.bind(_assert_this_initialized(_this));
25465
+ _this._onBorderChange = _this._onBorderChange.bind(_assert_this_initialized(_this));
25466
+ // @ts-ignore
25467
+ _this._region._onValueChanged = _this._onRegionChange;
25468
+ // @ts-ignore
25469
+ _this._pivot._onValueChanged = _this._onPivotChange;
25470
+ // @ts-ignore
25471
+ _this._border._onValueChanged = _this._onBorderChange;
25378
25472
  region && _this._region.copyFrom(region);
25379
25473
  pivot && _this._pivot.copyFrom(pivot);
25380
25474
  border && _this._border.copyFrom(border);
@@ -25515,6 +25609,34 @@
25515
25609
  }
25516
25610
  this._updateFlagManager.dispatch(type);
25517
25611
  };
25612
+ _proto._onRegionChange = function _onRegionChange() {
25613
+ var _this = this, region = _this._region;
25614
+ // @ts-ignore
25615
+ region._onValueChanged = null;
25616
+ var x = MathUtil$1.clamp(region.x, 0, 1);
25617
+ var y = MathUtil$1.clamp(region.y, 0, 1);
25618
+ region.set(x, y, MathUtil$1.clamp(region.width, 0, 1 - x), MathUtil$1.clamp(region.height, 0, 1 - y));
25619
+ this._dispatchSpriteChange(SpriteModifyFlags.region);
25620
+ if (this._customWidth === undefined || this._customHeight === undefined) {
25621
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
25622
+ }
25623
+ // @ts-ignore
25624
+ region._onValueChanged = this._onRegionChange;
25625
+ };
25626
+ _proto._onPivotChange = function _onPivotChange() {
25627
+ this._dispatchSpriteChange(SpriteModifyFlags.pivot);
25628
+ };
25629
+ _proto._onBorderChange = function _onBorderChange() {
25630
+ var _this = this, border = _this._border;
25631
+ // @ts-ignore
25632
+ border._onValueChanged = null;
25633
+ var x = MathUtil$1.clamp(border.x, 0, 1);
25634
+ var y = MathUtil$1.clamp(border.y, 0, 1);
25635
+ border.set(x, y, MathUtil$1.clamp(border.z, 0, 1 - x), MathUtil$1.clamp(border.w, 0, 1 - y));
25636
+ this._dispatchSpriteChange(SpriteModifyFlags.border);
25637
+ // @ts-ignore
25638
+ border._onValueChanged = this._onBorderChange;
25639
+ };
25518
25640
  _create_class$3(Sprite, [
25519
25641
  {
25520
25642
  key: "texture",
@@ -25634,14 +25756,7 @@
25634
25756
  return this._region;
25635
25757
  },
25636
25758
  set: function set(value) {
25637
- var region = this._region;
25638
- var x = MathUtil$1.clamp(value.x, 0, 1);
25639
- var y = MathUtil$1.clamp(value.y, 0, 1);
25640
- region.set(x, y, MathUtil$1.clamp(value.width, 0, 1 - x), MathUtil$1.clamp(value.height, 0, 1 - y));
25641
- this._dispatchSpriteChange(SpriteModifyFlags.region);
25642
- if (this._customWidth === undefined || this._customHeight === undefined) {
25643
- this._dispatchSpriteChange(SpriteModifyFlags.size);
25644
- }
25759
+ this._region !== value && this._region.copyFrom(value);
25645
25760
  }
25646
25761
  },
25647
25762
  {
@@ -25653,16 +25768,7 @@
25653
25768
  return this._pivot;
25654
25769
  },
25655
25770
  set: function set(value) {
25656
- var pivot = this._pivot;
25657
- if (pivot === value) {
25658
- this._dispatchSpriteChange(SpriteModifyFlags.pivot);
25659
- } else {
25660
- var x = value.x, y = value.y;
25661
- if (pivot.x !== x || pivot.y !== y) {
25662
- pivot.set(x, y);
25663
- this._dispatchSpriteChange(SpriteModifyFlags.pivot);
25664
- }
25665
- }
25771
+ this._pivot !== value && this._pivot.copyFrom(value);
25666
25772
  }
25667
25773
  },
25668
25774
  {
@@ -25677,11 +25783,7 @@
25677
25783
  return this._border;
25678
25784
  },
25679
25785
  set: function set(value) {
25680
- var border = this._border;
25681
- var x = MathUtil$1.clamp(value.x, 0, 1);
25682
- var y = MathUtil$1.clamp(value.y, 0, 1);
25683
- border.set(x, y, MathUtil$1.clamp(value.z, 0, 1 - x), MathUtil$1.clamp(value.w, 0, 1 - y));
25684
- this._dispatchSpriteChange(SpriteModifyFlags.border);
25786
+ this._border !== value && this._border.copyFrom(value);
25685
25787
  }
25686
25788
  }
25687
25789
  ]);
@@ -33727,7 +33829,8 @@
33727
33829
  var shArray = new Float32Array(arraybuffer, 0, 27);
33728
33830
  var shByteLength = 27 * 4;
33729
33831
  var size = (_ref = new Uint16Array(arraybuffer, shByteLength, 1)) == null ? void 0 : _ref[0];
33730
- var texture = new TextureCube(resourceManager.engine, size);
33832
+ var engine = resourceManager.engine;
33833
+ var texture = new TextureCube(engine, size);
33731
33834
  texture.filterMode = exports.TextureFilterMode.Trilinear;
33732
33835
  var mipmapCount = texture.mipmapCount;
33733
33836
  var offset = shByteLength + 2;
@@ -33740,7 +33843,7 @@
33740
33843
  texture.setPixelBuffer(exports.TextureCubeFace.PositiveX + face, data, mipLevel);
33741
33844
  }
33742
33845
  }
33743
- var ambientLight = new AmbientLight();
33846
+ var ambientLight = new AmbientLight(engine);
33744
33847
  var sh = new SphericalHarmonics3();
33745
33848
  ambientLight.diffuseMode = exports.DiffuseMode.SphericalHarmonics;
33746
33849
  sh.copyFromArray(shArray);
@@ -35883,8 +35986,14 @@
35883
35986
  resourceManager.addContentRestorer(restorer);
35884
35987
  masterPromiseInfo.resolve(glTFResource);
35885
35988
  }).catch(function(e) {
35886
- console.error(e);
35887
- masterPromiseInfo.reject("Error loading glTF model from " + url + " .");
35989
+ var msg = "Error loading glTF model from " + url + " .";
35990
+ Logger.error(msg);
35991
+ masterPromiseInfo.reject(msg);
35992
+ context.defaultSceneRootPromiseInfo.reject(e);
35993
+ context.texturesPromiseInfo.reject(e);
35994
+ context.materialsPromiseInfo.reject(e);
35995
+ context.meshesPromiseInfo.reject(e);
35996
+ context.animationClipsPromiseInfo.reject(e);
35888
35997
  });
35889
35998
  return context.promiseMap;
35890
35999
  };
@@ -37406,7 +37515,7 @@
37406
37515
  decode(data, resourceManager.engine).then(function(mesh) {
37407
37516
  resolve(mesh);
37408
37517
  });
37409
- });
37518
+ }).catch(reject);
37410
37519
  });
37411
37520
  };
37412
37521
  return MeshLoader;
@@ -37424,14 +37533,14 @@
37424
37533
  var _proto = EditorTextureLoader.prototype;
37425
37534
  _proto.load = function load(item, resourceManager) {
37426
37535
  var _this = this;
37427
- return new AssetPromise(function(resolve) {
37536
+ return new AssetPromise(function(resolve, reject) {
37428
37537
  _this.request(item.url, {
37429
37538
  type: "arraybuffer"
37430
37539
  }).then(function(data) {
37431
37540
  decode(data, resourceManager.engine).then(function(texture) {
37432
37541
  resolve(texture);
37433
37542
  });
37434
- });
37543
+ }).catch(reject);
37435
37544
  });
37436
37545
  };
37437
37546
  return EditorTextureLoader;
@@ -38296,7 +38405,7 @@
38296
38405
  ], GALACEAN_animation_event);
38297
38406
 
38298
38407
  //@ts-ignore
38299
- var version = "1.0.0-beta.14";
38408
+ var version = "1.0.0-beta.16";
38300
38409
  console.log("Galacean engine version: " + version);
38301
38410
  for(var key in CoreObjects){
38302
38411
  Loader.registerClass(key, CoreObjects[key]);