@galacean/engine 1.0.0-beta.15 → 1.0.0-beta.17
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 +602 -428
- package/dist/browser.min.js +1 -1
- package/dist/main.js +1 -1
- package/dist/miniprogram.js +1 -1
- package/dist/module.js +1 -1
- package/package.json +5 -5
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.
|
|
4660
|
-
this.
|
|
4661
|
-
this.
|
|
4662
|
-
this.
|
|
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.
|
|
4674
|
-
this.
|
|
4675
|
-
this.
|
|
4676
|
-
this.
|
|
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.
|
|
4691
|
-
this.
|
|
4692
|
-
this.
|
|
4693
|
-
this.
|
|
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)
|
|
7828
|
-
|
|
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
|
-
//
|
|
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;
|
|
@@ -9566,6 +9628,7 @@
|
|
|
9566
9628
|
cloneEntity._hookResource = hookResource;
|
|
9567
9629
|
hookResource._addReferCount(1);
|
|
9568
9630
|
}
|
|
9631
|
+
cloneEntity.layer = this.layer;
|
|
9569
9632
|
cloneEntity._isActive = this._isActive;
|
|
9570
9633
|
cloneEntity.transform.localMatrix = this.transform.localMatrix;
|
|
9571
9634
|
var children = this._children;
|
|
@@ -13154,31 +13217,18 @@
|
|
|
13154
13217
|
};
|
|
13155
13218
|
/**
|
|
13156
13219
|
* @internal
|
|
13157
|
-
*/ _proto.
|
|
13220
|
+
*/ _proto._updateSunLightIndex = function _updateSunLightIndex() {
|
|
13158
13221
|
var directLights = this._directLights;
|
|
13159
|
-
var
|
|
13160
|
-
|
|
13161
|
-
|
|
13162
|
-
|
|
13163
|
-
var
|
|
13164
|
-
|
|
13165
|
-
|
|
13166
|
-
|
|
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
|
-
}
|
|
13222
|
+
var index = this._getSunLightIndex();
|
|
13223
|
+
// -1 means no sun light, 0 means the first direct light already is sun light
|
|
13224
|
+
if (index > 0) {
|
|
13225
|
+
var firstLight = directLights.get(0);
|
|
13226
|
+
var sunLight = directLights.get(index);
|
|
13227
|
+
directLights.set(0, sunLight);
|
|
13228
|
+
directLights.set(index, firstLight);
|
|
13229
|
+
sunLight._lightIndex = 0;
|
|
13230
|
+
firstLight._lightIndex = index;
|
|
13180
13231
|
}
|
|
13181
|
-
return sunLightIndex;
|
|
13182
13232
|
};
|
|
13183
13233
|
/**
|
|
13184
13234
|
* @internal
|
|
@@ -13227,6 +13277,32 @@
|
|
|
13227
13277
|
this._pointLights.garbageCollection();
|
|
13228
13278
|
this._directLights.garbageCollection();
|
|
13229
13279
|
};
|
|
13280
|
+
_proto._getSunLightIndex = function _getSunLightIndex() {
|
|
13281
|
+
var directLights = this._directLights;
|
|
13282
|
+
var sunLightIndex = -1;
|
|
13283
|
+
var maxIntensity = Number.NEGATIVE_INFINITY;
|
|
13284
|
+
var hasShadowLight = false;
|
|
13285
|
+
for(var i = 0, n = directLights.length; i < n; i++){
|
|
13286
|
+
var directLight = directLights.get(i);
|
|
13287
|
+
if (directLight.shadowType !== exports.ShadowType.None && !hasShadowLight) {
|
|
13288
|
+
maxIntensity = Number.NEGATIVE_INFINITY;
|
|
13289
|
+
hasShadowLight = true;
|
|
13290
|
+
}
|
|
13291
|
+
var intensity = directLight.intensity * directLight.color.getBrightness();
|
|
13292
|
+
if (hasShadowLight) {
|
|
13293
|
+
if (directLight.shadowType !== exports.ShadowType.None && maxIntensity < intensity) {
|
|
13294
|
+
maxIntensity = intensity;
|
|
13295
|
+
sunLightIndex = i;
|
|
13296
|
+
}
|
|
13297
|
+
} else {
|
|
13298
|
+
if (maxIntensity < intensity) {
|
|
13299
|
+
maxIntensity = intensity;
|
|
13300
|
+
sunLightIndex = i;
|
|
13301
|
+
}
|
|
13302
|
+
}
|
|
13303
|
+
}
|
|
13304
|
+
return sunLightIndex;
|
|
13305
|
+
};
|
|
13230
13306
|
return LightManager;
|
|
13231
13307
|
}();
|
|
13232
13308
|
/**
|
|
@@ -14383,7 +14459,7 @@
|
|
|
14383
14459
|
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
|
|
14384
14460
|
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
|
|
14385
14461
|
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
|
|
14386
|
-
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()
|
|
14462
|
+
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
|
|
14387
14463
|
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
|
|
14388
14464
|
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
|
|
14389
14465
|
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
|
|
@@ -14403,7 +14479,7 @@
|
|
|
14403
14479
|
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
|
|
14404
14480
|
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
|
|
14405
14481
|
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
|
|
14406
|
-
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()
|
|
14482
|
+
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
|
|
14407
14483
|
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
|
|
14408
14484
|
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
|
|
14409
14485
|
var PBRShaderLib = {
|
|
@@ -20617,20 +20693,25 @@
|
|
|
20617
20693
|
})(exports.DiffuseMode || (exports.DiffuseMode = {}));
|
|
20618
20694
|
/**
|
|
20619
20695
|
* Ambient light.
|
|
20620
|
-
*/ var AmbientLight = /*#__PURE__*/ function() {
|
|
20621
|
-
var AmbientLight = function AmbientLight() {
|
|
20622
|
-
|
|
20623
|
-
|
|
20624
|
-
|
|
20625
|
-
|
|
20626
|
-
|
|
20627
|
-
|
|
20628
|
-
|
|
20696
|
+
*/ var AmbientLight = /*#__PURE__*/ function(ReferResource) {
|
|
20697
|
+
var AmbientLight = function AmbientLight(engine) {
|
|
20698
|
+
var _this;
|
|
20699
|
+
_this = ReferResource.call(this, engine) || this;
|
|
20700
|
+
_this._diffuseSolidColor = new Color$1(0.212, 0.227, 0.259);
|
|
20701
|
+
_this._diffuseIntensity = 1.0;
|
|
20702
|
+
_this._specularIntensity = 1.0;
|
|
20703
|
+
_this._diffuseMode = exports.DiffuseMode.SolidColor;
|
|
20704
|
+
_this._shArray = new Float32Array(27);
|
|
20705
|
+
_this._scenes = [];
|
|
20706
|
+
_this._specularTextureDecodeRGBM = false;
|
|
20707
|
+
return _this;
|
|
20629
20708
|
};
|
|
20709
|
+
_inherits$2(AmbientLight, ReferResource);
|
|
20630
20710
|
var _proto = AmbientLight.prototype;
|
|
20631
20711
|
/**
|
|
20632
20712
|
* @internal
|
|
20633
20713
|
*/ _proto._addToScene = function _addToScene(scene) {
|
|
20714
|
+
this._addReferCount(1);
|
|
20634
20715
|
this._scenes.push(scene);
|
|
20635
20716
|
var shaderData = scene.shaderData;
|
|
20636
20717
|
shaderData.setColor(AmbientLight._diffuseColorProperty, this._diffuseSolidColor);
|
|
@@ -20644,9 +20725,13 @@
|
|
|
20644
20725
|
/**
|
|
20645
20726
|
* @internal
|
|
20646
20727
|
*/ _proto._removeFromScene = function _removeFromScene(scene) {
|
|
20728
|
+
this._addReferCount(-1);
|
|
20647
20729
|
var scenes = this._scenes;
|
|
20648
20730
|
var index = scenes.indexOf(scene);
|
|
20649
20731
|
scenes.splice(index, 1);
|
|
20732
|
+
var shaderData = scene.shaderData;
|
|
20733
|
+
shaderData.setTexture(AmbientLight._specularTextureProperty, null);
|
|
20734
|
+
shaderData.disableMacro(AmbientLight._specularMacro);
|
|
20650
20735
|
};
|
|
20651
20736
|
_proto._setDiffuseMode = function _setDiffuseMode(sceneShaderData) {
|
|
20652
20737
|
if (this._diffuseMode === exports.DiffuseMode.SphericalHarmonics) {
|
|
@@ -20834,7 +20919,7 @@
|
|
|
20834
20919
|
}
|
|
20835
20920
|
]);
|
|
20836
20921
|
return AmbientLight;
|
|
20837
|
-
}();
|
|
20922
|
+
}(ReferResource);
|
|
20838
20923
|
(function() {
|
|
20839
20924
|
AmbientLight._shMacro = ShaderMacro.getByName("SCENE_USE_SH");
|
|
20840
20925
|
})();
|
|
@@ -20890,7 +20975,7 @@
|
|
|
20890
20975
|
_this.name = name || "";
|
|
20891
20976
|
var shaderData = _this.shaderData;
|
|
20892
20977
|
shaderData._addReferCount(1);
|
|
20893
|
-
_this.ambientLight = new AmbientLight();
|
|
20978
|
+
_this.ambientLight = new AmbientLight(engine);
|
|
20894
20979
|
engine.sceneManager._allScenes.push(_assert_this_initialized(_this));
|
|
20895
20980
|
shaderData.enableMacro("SCENE_FOG_MODE", _this._fogMode.toString());
|
|
20896
20981
|
shaderData.enableMacro("SCENE_SHADOW_CASCADED_COUNT", _this.shadowCascades.toString());
|
|
@@ -20998,6 +21083,7 @@
|
|
|
20998
21083
|
if (this._destroyed) {
|
|
20999
21084
|
return;
|
|
21000
21085
|
}
|
|
21086
|
+
EngineObject.prototype.destroy.call(this);
|
|
21001
21087
|
this._destroy();
|
|
21002
21088
|
var allScenes = this.engine.sceneManager._allScenes;
|
|
21003
21089
|
allScenes.splice(allScenes.indexOf(this), 1);
|
|
@@ -21040,9 +21126,9 @@
|
|
|
21040
21126
|
var lightManager = engine._lightManager;
|
|
21041
21127
|
engine.time._updateSceneShaderData(shaderData);
|
|
21042
21128
|
lightManager._updateShaderData(this.shaderData);
|
|
21043
|
-
|
|
21044
|
-
if (
|
|
21045
|
-
var sunlight = lightManager._directLights.get(
|
|
21129
|
+
lightManager._updateSunLightIndex();
|
|
21130
|
+
if (lightManager._directLights.length > 0) {
|
|
21131
|
+
var sunlight = lightManager._directLights.get(0);
|
|
21046
21132
|
shaderData.setColor(Scene._sunlightColorProperty, sunlight._getLightIntensityColor());
|
|
21047
21133
|
shaderData.setVector3(Scene._sunlightDirectionProperty, sunlight.direction);
|
|
21048
21134
|
this._sunLight = sunlight;
|
|
@@ -21077,6 +21163,7 @@
|
|
|
21077
21163
|
}
|
|
21078
21164
|
this._activeCameras.length = 0;
|
|
21079
21165
|
this.background.destroy();
|
|
21166
|
+
this._ambientLight && this._ambientLight._removeFromScene(this);
|
|
21080
21167
|
this.shaderData._addReferCount(-1);
|
|
21081
21168
|
};
|
|
21082
21169
|
_proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
|
|
@@ -21303,10 +21390,9 @@
|
|
|
21303
21390
|
* @internal
|
|
21304
21391
|
*/ _proto._destroyAllScene = function _destroyAllScene() {
|
|
21305
21392
|
var allScenes = this._allScenes;
|
|
21306
|
-
|
|
21307
|
-
allScenes[
|
|
21393
|
+
while(allScenes[0]){
|
|
21394
|
+
allScenes[0].destroy();
|
|
21308
21395
|
}
|
|
21309
|
-
allScenes.length = 0;
|
|
21310
21396
|
};
|
|
21311
21397
|
_create_class$3(SceneManager, [
|
|
21312
21398
|
{
|
|
@@ -23048,9 +23134,8 @@
|
|
|
23048
23134
|
var lightUp = this._lightUp;
|
|
23049
23135
|
var lightSide = this._lightSide;
|
|
23050
23136
|
var lightForward = shadowSliceData.virtualCamera.forward;
|
|
23051
|
-
var
|
|
23052
|
-
if (
|
|
23053
|
-
var light = camera.scene._sunLight;
|
|
23137
|
+
var light = camera.scene._sunLight;
|
|
23138
|
+
if (light) {
|
|
23054
23139
|
var shadowFar = Math.min(camera.scene.shadowDistance, camera.farClipPlane);
|
|
23055
23140
|
this._getCascadesSplitDistance(shadowFar);
|
|
23056
23141
|
// prepare render target
|
|
@@ -23063,7 +23148,7 @@
|
|
|
23063
23148
|
rhi.clearRenderTarget(engine, exports.CameraClearFlags.All, CascadedShadowCasterPass._clearColor);
|
|
23064
23149
|
}
|
|
23065
23150
|
this._shadowInfos.x = light.shadowStrength;
|
|
23066
|
-
this._shadowInfos.z =
|
|
23151
|
+
this._shadowInfos.z = 0; // @todo: sun light index always 0
|
|
23067
23152
|
// prepare light and camera direction
|
|
23068
23153
|
Matrix.rotationQuaternion(light.entity.transform.worldRotationQuaternion, lightWorld);
|
|
23069
23154
|
lightSide.set(lightWorldE[0], lightWorldE[1], lightWorldE[2]);
|
|
@@ -25376,6 +25461,15 @@
|
|
|
25376
25461
|
_this._dirtyUpdateFlag = 0x7;
|
|
25377
25462
|
/** @internal */ _this._updateFlagManager = new UpdateFlagManager();
|
|
25378
25463
|
_this._texture = texture;
|
|
25464
|
+
_this._onRegionChange = _this._onRegionChange.bind(_assert_this_initialized(_this));
|
|
25465
|
+
_this._onPivotChange = _this._onPivotChange.bind(_assert_this_initialized(_this));
|
|
25466
|
+
_this._onBorderChange = _this._onBorderChange.bind(_assert_this_initialized(_this));
|
|
25467
|
+
// @ts-ignore
|
|
25468
|
+
_this._region._onValueChanged = _this._onRegionChange;
|
|
25469
|
+
// @ts-ignore
|
|
25470
|
+
_this._pivot._onValueChanged = _this._onPivotChange;
|
|
25471
|
+
// @ts-ignore
|
|
25472
|
+
_this._border._onValueChanged = _this._onBorderChange;
|
|
25379
25473
|
region && _this._region.copyFrom(region);
|
|
25380
25474
|
pivot && _this._pivot.copyFrom(pivot);
|
|
25381
25475
|
border && _this._border.copyFrom(border);
|
|
@@ -25516,6 +25610,34 @@
|
|
|
25516
25610
|
}
|
|
25517
25611
|
this._updateFlagManager.dispatch(type);
|
|
25518
25612
|
};
|
|
25613
|
+
_proto._onRegionChange = function _onRegionChange() {
|
|
25614
|
+
var _this = this, region = _this._region;
|
|
25615
|
+
// @ts-ignore
|
|
25616
|
+
region._onValueChanged = null;
|
|
25617
|
+
var x = MathUtil$1.clamp(region.x, 0, 1);
|
|
25618
|
+
var y = MathUtil$1.clamp(region.y, 0, 1);
|
|
25619
|
+
region.set(x, y, MathUtil$1.clamp(region.width, 0, 1 - x), MathUtil$1.clamp(region.height, 0, 1 - y));
|
|
25620
|
+
this._dispatchSpriteChange(SpriteModifyFlags.region);
|
|
25621
|
+
if (this._customWidth === undefined || this._customHeight === undefined) {
|
|
25622
|
+
this._dispatchSpriteChange(SpriteModifyFlags.size);
|
|
25623
|
+
}
|
|
25624
|
+
// @ts-ignore
|
|
25625
|
+
region._onValueChanged = this._onRegionChange;
|
|
25626
|
+
};
|
|
25627
|
+
_proto._onPivotChange = function _onPivotChange() {
|
|
25628
|
+
this._dispatchSpriteChange(SpriteModifyFlags.pivot);
|
|
25629
|
+
};
|
|
25630
|
+
_proto._onBorderChange = function _onBorderChange() {
|
|
25631
|
+
var _this = this, border = _this._border;
|
|
25632
|
+
// @ts-ignore
|
|
25633
|
+
border._onValueChanged = null;
|
|
25634
|
+
var x = MathUtil$1.clamp(border.x, 0, 1);
|
|
25635
|
+
var y = MathUtil$1.clamp(border.y, 0, 1);
|
|
25636
|
+
border.set(x, y, MathUtil$1.clamp(border.z, 0, 1 - x), MathUtil$1.clamp(border.w, 0, 1 - y));
|
|
25637
|
+
this._dispatchSpriteChange(SpriteModifyFlags.border);
|
|
25638
|
+
// @ts-ignore
|
|
25639
|
+
border._onValueChanged = this._onBorderChange;
|
|
25640
|
+
};
|
|
25519
25641
|
_create_class$3(Sprite, [
|
|
25520
25642
|
{
|
|
25521
25643
|
key: "texture",
|
|
@@ -25635,14 +25757,7 @@
|
|
|
25635
25757
|
return this._region;
|
|
25636
25758
|
},
|
|
25637
25759
|
set: function set(value) {
|
|
25638
|
-
|
|
25639
|
-
var x = MathUtil$1.clamp(value.x, 0, 1);
|
|
25640
|
-
var y = MathUtil$1.clamp(value.y, 0, 1);
|
|
25641
|
-
region.set(x, y, MathUtil$1.clamp(value.width, 0, 1 - x), MathUtil$1.clamp(value.height, 0, 1 - y));
|
|
25642
|
-
this._dispatchSpriteChange(SpriteModifyFlags.region);
|
|
25643
|
-
if (this._customWidth === undefined || this._customHeight === undefined) {
|
|
25644
|
-
this._dispatchSpriteChange(SpriteModifyFlags.size);
|
|
25645
|
-
}
|
|
25760
|
+
this._region !== value && this._region.copyFrom(value);
|
|
25646
25761
|
}
|
|
25647
25762
|
},
|
|
25648
25763
|
{
|
|
@@ -25654,16 +25769,7 @@
|
|
|
25654
25769
|
return this._pivot;
|
|
25655
25770
|
},
|
|
25656
25771
|
set: function set(value) {
|
|
25657
|
-
|
|
25658
|
-
if (pivot === value) {
|
|
25659
|
-
this._dispatchSpriteChange(SpriteModifyFlags.pivot);
|
|
25660
|
-
} else {
|
|
25661
|
-
var x = value.x, y = value.y;
|
|
25662
|
-
if (pivot.x !== x || pivot.y !== y) {
|
|
25663
|
-
pivot.set(x, y);
|
|
25664
|
-
this._dispatchSpriteChange(SpriteModifyFlags.pivot);
|
|
25665
|
-
}
|
|
25666
|
-
}
|
|
25772
|
+
this._pivot !== value && this._pivot.copyFrom(value);
|
|
25667
25773
|
}
|
|
25668
25774
|
},
|
|
25669
25775
|
{
|
|
@@ -25678,11 +25784,7 @@
|
|
|
25678
25784
|
return this._border;
|
|
25679
25785
|
},
|
|
25680
25786
|
set: function set(value) {
|
|
25681
|
-
|
|
25682
|
-
var x = MathUtil$1.clamp(value.x, 0, 1);
|
|
25683
|
-
var y = MathUtil$1.clamp(value.y, 0, 1);
|
|
25684
|
-
border.set(x, y, MathUtil$1.clamp(value.z, 0, 1 - x), MathUtil$1.clamp(value.w, 0, 1 - y));
|
|
25685
|
-
this._dispatchSpriteChange(SpriteModifyFlags.border);
|
|
25787
|
+
this._border !== value && this._border.copyFrom(value);
|
|
25686
25788
|
}
|
|
25687
25789
|
}
|
|
25688
25790
|
]);
|
|
@@ -33630,7 +33732,8 @@
|
|
|
33630
33732
|
state.wrapMode = wrapMode;
|
|
33631
33733
|
state.clipStartTime = clipStartNormalizedTime;
|
|
33632
33734
|
state.clipEndTime = clipEndNormalizedTime;
|
|
33633
|
-
|
|
33735
|
+
var scriptsObject = JSON.parse(scripts);
|
|
33736
|
+
scriptsObject == null ? void 0 : scriptsObject.forEach(function(script) {
|
|
33634
33737
|
state.addStateMachineScript(Loader.getClass(script));
|
|
33635
33738
|
});
|
|
33636
33739
|
if (clipData) {
|
|
@@ -33728,7 +33831,8 @@
|
|
|
33728
33831
|
var shArray = new Float32Array(arraybuffer, 0, 27);
|
|
33729
33832
|
var shByteLength = 27 * 4;
|
|
33730
33833
|
var size = (_ref = new Uint16Array(arraybuffer, shByteLength, 1)) == null ? void 0 : _ref[0];
|
|
33731
|
-
var
|
|
33834
|
+
var engine = resourceManager.engine;
|
|
33835
|
+
var texture = new TextureCube(engine, size);
|
|
33732
33836
|
texture.filterMode = exports.TextureFilterMode.Trilinear;
|
|
33733
33837
|
var mipmapCount = texture.mipmapCount;
|
|
33734
33838
|
var offset = shByteLength + 2;
|
|
@@ -33741,7 +33845,7 @@
|
|
|
33741
33845
|
texture.setPixelBuffer(exports.TextureCubeFace.PositiveX + face, data, mipLevel);
|
|
33742
33846
|
}
|
|
33743
33847
|
}
|
|
33744
|
-
var ambientLight = new AmbientLight();
|
|
33848
|
+
var ambientLight = new AmbientLight(engine);
|
|
33745
33849
|
var sh = new SphericalHarmonics3();
|
|
33746
33850
|
ambientLight.diffuseMode = exports.DiffuseMode.SphericalHarmonics;
|
|
33747
33851
|
sh.copyFromArray(shArray);
|
|
@@ -34195,6 +34299,11 @@
|
|
|
34195
34299
|
promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
|
|
34196
34300
|
};
|
|
34197
34301
|
var _proto = GLTFParserContext.prototype;
|
|
34302
|
+
/**
|
|
34303
|
+
* Get all the buffer data.
|
|
34304
|
+
*/ _proto.getBuffers = function getBuffers() {
|
|
34305
|
+
return Promise.resolve(this._buffers);
|
|
34306
|
+
};
|
|
34198
34307
|
_proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
|
|
34199
34308
|
var promise = new AssetPromise(function(resolve, reject, setProgress, onCancel) {
|
|
34200
34309
|
promiseInfo.resolve = resolve;
|
|
@@ -34314,44 +34423,45 @@
|
|
|
34314
34423
|
}
|
|
34315
34424
|
};
|
|
34316
34425
|
GLTFUtils.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
|
|
34317
|
-
var buffers = context.buffers;
|
|
34318
34426
|
var componentType = accessor.componentType;
|
|
34319
34427
|
var bufferView = bufferViews[accessor.bufferView];
|
|
34320
|
-
|
|
34321
|
-
|
|
34322
|
-
|
|
34323
|
-
|
|
34324
|
-
|
|
34325
|
-
|
|
34326
|
-
|
|
34327
|
-
|
|
34328
|
-
|
|
34329
|
-
|
|
34330
|
-
|
|
34331
|
-
|
|
34332
|
-
|
|
34333
|
-
|
|
34334
|
-
|
|
34335
|
-
|
|
34336
|
-
|
|
34337
|
-
|
|
34338
|
-
|
|
34339
|
-
|
|
34340
|
-
|
|
34341
|
-
|
|
34342
|
-
|
|
34428
|
+
return context.getBuffers().then(function(buffers) {
|
|
34429
|
+
var bufferIndex = bufferView.buffer;
|
|
34430
|
+
var buffer = buffers[bufferIndex];
|
|
34431
|
+
var bufferByteOffset = bufferView.byteOffset || 0;
|
|
34432
|
+
var byteOffset = accessor.byteOffset || 0;
|
|
34433
|
+
var TypedArray = GLTFUtils.getComponentType(componentType);
|
|
34434
|
+
var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
34435
|
+
var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
|
|
34436
|
+
var elementStride = dataElementSize * dataElementBytes;
|
|
34437
|
+
var accessorCount = accessor.count;
|
|
34438
|
+
var bufferStride = bufferView.byteStride;
|
|
34439
|
+
var bufferInfo;
|
|
34440
|
+
// According to the glTF official documentation only byteStride not undefined is allowed
|
|
34441
|
+
if (bufferStride !== undefined && bufferStride !== elementStride) {
|
|
34442
|
+
var bufferSlice = Math.floor(byteOffset / bufferStride);
|
|
34443
|
+
var bufferCacheKey = accessor.bufferView + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
|
|
34444
|
+
var accessorBufferCache = context.accessorBufferCache;
|
|
34445
|
+
bufferInfo = accessorBufferCache[bufferCacheKey];
|
|
34446
|
+
if (!bufferInfo) {
|
|
34447
|
+
var offset = bufferByteOffset + bufferSlice * bufferStride;
|
|
34448
|
+
var count = accessorCount * (bufferStride / dataElementBytes);
|
|
34449
|
+
var data = new TypedArray(buffer, offset, count);
|
|
34450
|
+
accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
|
|
34451
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
|
|
34452
|
+
}
|
|
34453
|
+
} else {
|
|
34454
|
+
var offset1 = bufferByteOffset + byteOffset;
|
|
34455
|
+
var count1 = accessorCount * dataElementSize;
|
|
34456
|
+
var data1 = new TypedArray(buffer, offset1, count1);
|
|
34457
|
+
bufferInfo = new BufferInfo(data1, false, elementStride);
|
|
34458
|
+
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
|
|
34343
34459
|
}
|
|
34344
|
-
|
|
34345
|
-
|
|
34346
|
-
|
|
34347
|
-
|
|
34348
|
-
|
|
34349
|
-
bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
|
|
34350
|
-
}
|
|
34351
|
-
if (accessor.sparse) {
|
|
34352
|
-
GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
|
|
34353
|
-
}
|
|
34354
|
-
return bufferInfo;
|
|
34460
|
+
if (accessor.sparse) {
|
|
34461
|
+
GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
|
|
34462
|
+
}
|
|
34463
|
+
return bufferInfo;
|
|
34464
|
+
});
|
|
34355
34465
|
};
|
|
34356
34466
|
/**
|
|
34357
34467
|
* @deprecated
|
|
@@ -34810,9 +34920,7 @@
|
|
|
34810
34920
|
_inherits(GLTFAnimationParser, GLTFParser1);
|
|
34811
34921
|
var _proto = GLTFAnimationParser.prototype;
|
|
34812
34922
|
_proto.parse = function parse(context) {
|
|
34813
|
-
var glTF = context.glTF;
|
|
34814
|
-
context.buffers;
|
|
34815
|
-
var glTFResource = context.glTFResource;
|
|
34923
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
34816
34924
|
glTFResource.entities;
|
|
34817
34925
|
var animations = glTF.animations;
|
|
34818
34926
|
glTF.accessors;
|
|
@@ -34824,106 +34932,120 @@
|
|
|
34824
34932
|
var animationClipCount = animations.length;
|
|
34825
34933
|
var animationClipPromises = [];
|
|
34826
34934
|
new Array(animationClipCount);
|
|
34935
|
+
var parseStandardPropertyPromises = new Array();
|
|
34827
34936
|
for(var i = 0; i < animationClipCount; i++){
|
|
34828
34937
|
var animationInfo = animations[i];
|
|
34829
34938
|
var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
|
|
34830
34939
|
var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
|
|
34831
34940
|
if (!animationClip) {
|
|
34832
34941
|
animationClip = new AnimationClip(name);
|
|
34833
|
-
GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
|
|
34942
|
+
parseStandardPropertyPromises.push(GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo));
|
|
34834
34943
|
}
|
|
34835
34944
|
animationClipPromises.push(animationClip);
|
|
34836
34945
|
}
|
|
34837
|
-
return AssetPromise.all(
|
|
34838
|
-
|
|
34839
|
-
|
|
34840
|
-
var
|
|
34841
|
-
|
|
34842
|
-
|
|
34843
|
-
|
|
34844
|
-
|
|
34946
|
+
return AssetPromise.all(parseStandardPropertyPromises).then(function() {
|
|
34947
|
+
return AssetPromise.all(animationClipPromises).then(function(animationClips) {
|
|
34948
|
+
glTFResource.animations = animationClips;
|
|
34949
|
+
for(var i = 0; i < glTF.animations.length; i++){
|
|
34950
|
+
var animationInfo = glTF.animations[i];
|
|
34951
|
+
GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
|
|
34952
|
+
}
|
|
34953
|
+
animationClipsPromiseInfo.resolve(animationClips);
|
|
34954
|
+
return animationClipsPromiseInfo.promise;
|
|
34955
|
+
});
|
|
34845
34956
|
});
|
|
34846
34957
|
};
|
|
34847
34958
|
/**
|
|
34848
34959
|
* @internal
|
|
34849
34960
|
*/ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
|
|
34961
|
+
var _loop = function _loop(j, m) {
|
|
34962
|
+
var gltfSampler = samplers[j];
|
|
34963
|
+
var inputAccessor = accessors[gltfSampler.input];
|
|
34964
|
+
var outputAccessor = accessors[gltfSampler.output];
|
|
34965
|
+
var promise = Promise.all([
|
|
34966
|
+
GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor),
|
|
34967
|
+
GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor)
|
|
34968
|
+
]).then(function(bufferInfos) {
|
|
34969
|
+
var input = bufferInfos[0].data;
|
|
34970
|
+
var output = bufferInfos[1].data;
|
|
34971
|
+
if (outputAccessor.normalized) {
|
|
34972
|
+
var scale = GLTFUtils.getNormalizedComponentScale(outputAccessor.componentType);
|
|
34973
|
+
var scaled = new Float32Array(output.length);
|
|
34974
|
+
for(var k = 0, v = output.length; k < v; k++){
|
|
34975
|
+
scaled[k] = output[k] * scale;
|
|
34976
|
+
}
|
|
34977
|
+
output = scaled;
|
|
34978
|
+
}
|
|
34979
|
+
var outputStride = output.length / input.length;
|
|
34980
|
+
var _gltfSampler_interpolation;
|
|
34981
|
+
var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
|
|
34982
|
+
var samplerInterpolation;
|
|
34983
|
+
switch(interpolation){
|
|
34984
|
+
case AnimationSamplerInterpolation.CubicSpine:
|
|
34985
|
+
samplerInterpolation = exports.InterpolationType.CubicSpine;
|
|
34986
|
+
break;
|
|
34987
|
+
case AnimationSamplerInterpolation.Step:
|
|
34988
|
+
samplerInterpolation = exports.InterpolationType.Step;
|
|
34989
|
+
break;
|
|
34990
|
+
case AnimationSamplerInterpolation.Linear:
|
|
34991
|
+
samplerInterpolation = exports.InterpolationType.Linear;
|
|
34992
|
+
break;
|
|
34993
|
+
}
|
|
34994
|
+
input[input.length - 1];
|
|
34995
|
+
sampleDataCollection.push({
|
|
34996
|
+
type: outputAccessor.type,
|
|
34997
|
+
interpolation: samplerInterpolation,
|
|
34998
|
+
input: input,
|
|
34999
|
+
output: output,
|
|
35000
|
+
outputSize: outputStride
|
|
35001
|
+
});
|
|
35002
|
+
});
|
|
35003
|
+
promises.push(promise);
|
|
35004
|
+
};
|
|
35005
|
+
var _this = this;
|
|
34850
35006
|
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
34851
35007
|
var entities = glTFResource.entities;
|
|
34852
35008
|
var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
|
|
34853
35009
|
var channels = animationInfo.channels, samplers = animationInfo.samplers;
|
|
34854
35010
|
var sampleDataCollection = new Array();
|
|
35011
|
+
var promises = new Array();
|
|
34855
35012
|
// parse samplers
|
|
34856
|
-
for(var j = 0, m = samplers.length; j < m; j++)
|
|
34857
|
-
|
|
34858
|
-
var
|
|
34859
|
-
|
|
34860
|
-
|
|
34861
|
-
|
|
34862
|
-
|
|
34863
|
-
var
|
|
34864
|
-
|
|
34865
|
-
|
|
34866
|
-
|
|
34867
|
-
}
|
|
34868
|
-
|
|
34869
|
-
|
|
34870
|
-
|
|
34871
|
-
|
|
34872
|
-
|
|
34873
|
-
|
|
34874
|
-
|
|
34875
|
-
|
|
34876
|
-
|
|
34877
|
-
|
|
34878
|
-
|
|
34879
|
-
|
|
34880
|
-
|
|
34881
|
-
|
|
34882
|
-
|
|
34883
|
-
|
|
34884
|
-
|
|
34885
|
-
|
|
34886
|
-
|
|
34887
|
-
|
|
34888
|
-
|
|
34889
|
-
|
|
34890
|
-
output: output,
|
|
34891
|
-
outputSize: outputStride
|
|
34892
|
-
});
|
|
34893
|
-
}
|
|
34894
|
-
for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
|
|
34895
|
-
var gltfChannel = channels[j1];
|
|
34896
|
-
var target = gltfChannel.target;
|
|
34897
|
-
var channelTargetEntity = entities[target.node];
|
|
34898
|
-
var relativePath = "";
|
|
34899
|
-
var entity = channelTargetEntity;
|
|
34900
|
-
while(entity.parent){
|
|
34901
|
-
relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
|
|
34902
|
-
entity = entity.parent;
|
|
34903
|
-
}
|
|
34904
|
-
var ComponentType = void 0;
|
|
34905
|
-
var propertyName = void 0;
|
|
34906
|
-
switch(target.path){
|
|
34907
|
-
case AnimationChannelTargetPath.TRANSLATION:
|
|
34908
|
-
ComponentType = Transform;
|
|
34909
|
-
propertyName = "position";
|
|
34910
|
-
break;
|
|
34911
|
-
case AnimationChannelTargetPath.ROTATION:
|
|
34912
|
-
ComponentType = Transform;
|
|
34913
|
-
propertyName = "rotationQuaternion";
|
|
34914
|
-
break;
|
|
34915
|
-
case AnimationChannelTargetPath.SCALE:
|
|
34916
|
-
ComponentType = Transform;
|
|
34917
|
-
propertyName = "scale";
|
|
34918
|
-
break;
|
|
34919
|
-
case AnimationChannelTargetPath.WEIGHTS:
|
|
34920
|
-
ComponentType = SkinnedMeshRenderer;
|
|
34921
|
-
propertyName = "blendShapeWeights";
|
|
34922
|
-
break;
|
|
35013
|
+
for(var j = 0, m = samplers.length; j < m; j++)_loop(j);
|
|
35014
|
+
return Promise.all(promises).then(function() {
|
|
35015
|
+
for(var j = 0, m = channels.length; j < m; j++){
|
|
35016
|
+
var gltfChannel = channels[j];
|
|
35017
|
+
var target = gltfChannel.target;
|
|
35018
|
+
var channelTargetEntity = entities[target.node];
|
|
35019
|
+
var relativePath = "";
|
|
35020
|
+
var entity = channelTargetEntity;
|
|
35021
|
+
while(entity.parent){
|
|
35022
|
+
relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
|
|
35023
|
+
entity = entity.parent;
|
|
35024
|
+
}
|
|
35025
|
+
var ComponentType = void 0;
|
|
35026
|
+
var propertyName = void 0;
|
|
35027
|
+
switch(target.path){
|
|
35028
|
+
case AnimationChannelTargetPath.TRANSLATION:
|
|
35029
|
+
ComponentType = Transform;
|
|
35030
|
+
propertyName = "position";
|
|
35031
|
+
break;
|
|
35032
|
+
case AnimationChannelTargetPath.ROTATION:
|
|
35033
|
+
ComponentType = Transform;
|
|
35034
|
+
propertyName = "rotationQuaternion";
|
|
35035
|
+
break;
|
|
35036
|
+
case AnimationChannelTargetPath.SCALE:
|
|
35037
|
+
ComponentType = Transform;
|
|
35038
|
+
propertyName = "scale";
|
|
35039
|
+
break;
|
|
35040
|
+
case AnimationChannelTargetPath.WEIGHTS:
|
|
35041
|
+
ComponentType = SkinnedMeshRenderer;
|
|
35042
|
+
propertyName = "blendShapeWeights";
|
|
35043
|
+
break;
|
|
35044
|
+
}
|
|
35045
|
+
var curve = _this._addCurve(target.path, gltfChannel, sampleDataCollection);
|
|
35046
|
+
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
34923
35047
|
}
|
|
34924
|
-
|
|
34925
|
-
animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
|
|
34926
|
-
}
|
|
35048
|
+
});
|
|
34927
35049
|
};
|
|
34928
35050
|
GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
|
|
34929
35051
|
var sampleData = sampleDataCollection[gltfChannel.sampler];
|
|
@@ -35017,20 +35139,18 @@
|
|
|
35017
35139
|
}).then(function(param) {
|
|
35018
35140
|
var glTF = param.glTF, buffers = param.buffers;
|
|
35019
35141
|
context.glTF = glTF;
|
|
35020
|
-
context.
|
|
35142
|
+
context._buffers = buffers;
|
|
35021
35143
|
});
|
|
35022
35144
|
} else {
|
|
35023
35145
|
return request(url, {
|
|
35024
35146
|
type: "json"
|
|
35025
35147
|
}).then(function(glTF) {
|
|
35026
35148
|
context.glTF = glTF;
|
|
35027
|
-
|
|
35149
|
+
context._buffers = Promise.all(glTF.buffers.map(function(buffer) {
|
|
35028
35150
|
var absoluteUrl = Utils.resolveAbsoluteUrl(url, buffer.uri);
|
|
35029
35151
|
restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
|
|
35030
35152
|
return request(absoluteUrl, requestConfig);
|
|
35031
|
-
}))
|
|
35032
|
-
context.buffers = buffers;
|
|
35033
|
-
});
|
|
35153
|
+
}));
|
|
35034
35154
|
});
|
|
35035
35155
|
}
|
|
35036
35156
|
};
|
|
@@ -35275,7 +35395,9 @@
|
|
|
35275
35395
|
}
|
|
35276
35396
|
}, function() {
|
|
35277
35397
|
var indexAccessor = glTF.accessors[gltfPrimitive.indices];
|
|
35278
|
-
return
|
|
35398
|
+
return context.getBuffers().then(function(buffers) {
|
|
35399
|
+
return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
|
|
35400
|
+
});
|
|
35279
35401
|
}, context.keepMeshData).then(resolve);
|
|
35280
35402
|
}
|
|
35281
35403
|
});
|
|
@@ -35285,7 +35407,7 @@
|
|
|
35285
35407
|
for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
|
|
35286
35408
|
meshPromises[i] = Promise.all(primitivePromises);
|
|
35287
35409
|
};
|
|
35288
|
-
var glTF = context.glTF,
|
|
35410
|
+
var glTF = context.glTF, glTFResource = context.glTFResource;
|
|
35289
35411
|
var engine = glTFResource.engine;
|
|
35290
35412
|
if (!glTF.meshes) return;
|
|
35291
35413
|
var meshesPromiseInfo = context.meshesPromiseInfo;
|
|
@@ -35300,8 +35422,109 @@
|
|
|
35300
35422
|
/**
|
|
35301
35423
|
* @internal
|
|
35302
35424
|
*/ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
35425
|
+
var _loop = function _loop(attribute) {
|
|
35426
|
+
var accessor = accessors[attributes[attribute]];
|
|
35427
|
+
var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor).then(function(accessorBuffer) {
|
|
35428
|
+
var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
|
|
35429
|
+
var accessorCount = accessor.count;
|
|
35430
|
+
var vertices = accessorBuffer.data;
|
|
35431
|
+
var vertexElement;
|
|
35432
|
+
var meshId = mesh.instanceId;
|
|
35433
|
+
var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
|
|
35434
|
+
var elementNormalized = accessor.normalized;
|
|
35435
|
+
var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
|
|
35436
|
+
var scaleFactor;
|
|
35437
|
+
elementNormalized && (scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType));
|
|
35438
|
+
var elementOffset;
|
|
35439
|
+
if (accessorBuffer.interleaved) {
|
|
35440
|
+
var byteOffset = accessor.byteOffset || 0;
|
|
35441
|
+
var stride = accessorBuffer.stride;
|
|
35442
|
+
elementOffset = byteOffset % stride;
|
|
35443
|
+
if (vertexBindingInfos[meshId] === undefined) {
|
|
35444
|
+
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
35445
|
+
var vertexBuffer = accessorBuffer.vertexBuffer;
|
|
35446
|
+
if (!vertexBuffer) {
|
|
35447
|
+
vertexBuffer = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices.byteLength, exports.BufferUsage.Static);
|
|
35448
|
+
vertexBuffer.setData(vertices);
|
|
35449
|
+
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
35450
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
|
|
35451
|
+
}
|
|
35452
|
+
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
35453
|
+
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
35454
|
+
} else {
|
|
35455
|
+
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
|
|
35456
|
+
}
|
|
35457
|
+
} else {
|
|
35458
|
+
elementOffset = 0;
|
|
35459
|
+
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
35460
|
+
var vertexBuffer1 = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices.byteLength, exports.BufferUsage.Static);
|
|
35461
|
+
vertexBuffer1.setData(vertices);
|
|
35462
|
+
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
|
|
35463
|
+
mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
|
|
35464
|
+
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
35465
|
+
}
|
|
35466
|
+
vertexElements.push(vertexElement);
|
|
35467
|
+
if (attribute === "POSITION") {
|
|
35468
|
+
vertexCount = accessorCount;
|
|
35469
|
+
var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
|
|
35470
|
+
if (accessor.min && accessor.max) {
|
|
35471
|
+
min.copyFromArray(accessor.min);
|
|
35472
|
+
max.copyFromArray(accessor.max);
|
|
35473
|
+
if (keepMeshData) {
|
|
35474
|
+
var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
35475
|
+
var stride1 = vertices.length / accessorCount;
|
|
35476
|
+
for(var j = 0; j < accessorCount; j++){
|
|
35477
|
+
var offset = baseOffset + j * stride1;
|
|
35478
|
+
var position = new Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
|
|
35479
|
+
elementNormalized && position.scale(scaleFactor);
|
|
35480
|
+
positions[j] = position;
|
|
35481
|
+
}
|
|
35482
|
+
}
|
|
35483
|
+
} else {
|
|
35484
|
+
var position1 = GLTFMeshParser._tempVector3;
|
|
35485
|
+
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
35486
|
+
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
35487
|
+
var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
35488
|
+
var stride2 = vertices.length / accessorCount;
|
|
35489
|
+
for(var j1 = 0; j1 < accessorCount; j1++){
|
|
35490
|
+
var offset1 = baseOffset1 + j1 * stride2;
|
|
35491
|
+
position1.copyFromArray(vertices, offset1);
|
|
35492
|
+
Vector3.min(min, position1, min);
|
|
35493
|
+
Vector3.max(max, position1, max);
|
|
35494
|
+
if (keepMeshData) {
|
|
35495
|
+
var clonePosition = position1.clone();
|
|
35496
|
+
elementNormalized && clonePosition.scale(scaleFactor);
|
|
35497
|
+
positions[j1] = clonePosition;
|
|
35498
|
+
}
|
|
35499
|
+
}
|
|
35500
|
+
}
|
|
35501
|
+
if (elementNormalized) {
|
|
35502
|
+
min.scale(scaleFactor);
|
|
35503
|
+
max.scale(scaleFactor);
|
|
35504
|
+
}
|
|
35505
|
+
} else if (attribute === "JOINTS_0" && keepMeshData) {
|
|
35506
|
+
var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
35507
|
+
var stride3 = vertices.length / accessorCount;
|
|
35508
|
+
for(var j2 = 0; j2 < accessorCount; j2++){
|
|
35509
|
+
var offset2 = baseOffset2 + j2 * stride3;
|
|
35510
|
+
var boneIndex = new Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
|
|
35511
|
+
elementNormalized && boneIndex.scale(scaleFactor);
|
|
35512
|
+
boneIndices[j2] = boneIndex;
|
|
35513
|
+
}
|
|
35514
|
+
} else if (attribute === "WEIGHTS_0" && keepMeshData) {
|
|
35515
|
+
var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
35516
|
+
var stride4 = vertices.length / accessorCount;
|
|
35517
|
+
for(var j3 = 0; j3 < accessorCount; j3++){
|
|
35518
|
+
var offset3 = baseOffset3 + j3 * stride4;
|
|
35519
|
+
var boneWeight = new Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
|
|
35520
|
+
elementNormalized && boneWeight.scale(scaleFactor);
|
|
35521
|
+
boneWeights[j3] = boneWeight;
|
|
35522
|
+
}
|
|
35523
|
+
}
|
|
35524
|
+
});
|
|
35525
|
+
promises.push(promise);
|
|
35526
|
+
};
|
|
35303
35527
|
var accessors = gltf.accessors;
|
|
35304
|
-
context.buffers;
|
|
35305
35528
|
var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
|
|
35306
35529
|
var engine = mesh.engine;
|
|
35307
35530
|
var vertexElements = new Array();
|
|
@@ -35315,145 +35538,65 @@
|
|
|
35315
35538
|
boneIndices = new Array(vertexCount);
|
|
35316
35539
|
boneWeights = new Array(vertexCount);
|
|
35317
35540
|
}
|
|
35318
|
-
|
|
35319
|
-
|
|
35320
|
-
|
|
35321
|
-
|
|
35322
|
-
|
|
35323
|
-
|
|
35324
|
-
|
|
35325
|
-
|
|
35326
|
-
|
|
35327
|
-
|
|
35328
|
-
|
|
35329
|
-
|
|
35330
|
-
|
|
35331
|
-
var elementOffset = void 0;
|
|
35332
|
-
if (accessorBuffer.interleaved) {
|
|
35333
|
-
var byteOffset = accessor.byteOffset || 0;
|
|
35334
|
-
var stride = accessorBuffer.stride;
|
|
35335
|
-
elementOffset = byteOffset % stride;
|
|
35336
|
-
if (vertexBindingInfos[meshId] === undefined) {
|
|
35337
|
-
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
|
|
35338
|
-
var vertexBuffer = accessorBuffer.vertexBuffer;
|
|
35339
|
-
if (!vertexBuffer) {
|
|
35340
|
-
vertexBuffer = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices.byteLength, exports.BufferUsage.Static);
|
|
35341
|
-
vertexBuffer.setData(vertices);
|
|
35342
|
-
accessorBuffer.vertexBuffer = vertexBuffer;
|
|
35343
|
-
meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
|
|
35344
|
-
}
|
|
35345
|
-
mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
|
|
35346
|
-
vertexBindingInfos[meshId] = bufferBindIndex++;
|
|
35347
|
-
} else {
|
|
35348
|
-
vertexElement = new VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
|
|
35349
|
-
}
|
|
35541
|
+
var promises = new Array();
|
|
35542
|
+
for(var attribute in attributes)_loop(attribute);
|
|
35543
|
+
return Promise.all(promises).then(function() {
|
|
35544
|
+
mesh.setVertexElements(vertexElements);
|
|
35545
|
+
// Indices
|
|
35546
|
+
if (indices !== undefined) {
|
|
35547
|
+
var indexAccessor = gltf.accessors[indices];
|
|
35548
|
+
var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor).then(function(accessorBuffer) {
|
|
35549
|
+
mesh.setIndices(accessorBuffer.data);
|
|
35550
|
+
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
35551
|
+
meshRestoreInfo.indexBuffer = accessorBuffer.restoreInfo;
|
|
35552
|
+
});
|
|
35553
|
+
promises.push(promise);
|
|
35350
35554
|
} else {
|
|
35351
|
-
|
|
35352
|
-
|
|
35353
|
-
|
|
35354
|
-
|
|
35355
|
-
|
|
35356
|
-
|
|
35357
|
-
|
|
35358
|
-
|
|
35359
|
-
|
|
35360
|
-
|
|
35361
|
-
|
|
35362
|
-
|
|
35363
|
-
|
|
35364
|
-
|
|
35365
|
-
|
|
35366
|
-
|
|
35367
|
-
|
|
35368
|
-
var stride1 = vertices.length / accessorCount;
|
|
35369
|
-
for(var j = 0; j < accessorCount; j++){
|
|
35370
|
-
var offset = baseOffset + j * stride1;
|
|
35371
|
-
var position = new Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
|
|
35372
|
-
elementNormalized && position.scale(scaleFactor);
|
|
35373
|
-
positions[j] = position;
|
|
35374
|
-
}
|
|
35375
|
-
}
|
|
35376
|
-
} else {
|
|
35377
|
-
var position1 = GLTFMeshParser._tempVector3;
|
|
35378
|
-
min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
|
|
35379
|
-
max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
|
|
35380
|
-
var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
35381
|
-
var stride2 = vertices.length / accessorCount;
|
|
35382
|
-
for(var j1 = 0; j1 < accessorCount; j1++){
|
|
35383
|
-
var offset1 = baseOffset1 + j1 * stride2;
|
|
35384
|
-
position1.copyFromArray(vertices, offset1);
|
|
35385
|
-
Vector3.min(min, position1, min);
|
|
35386
|
-
Vector3.max(max, position1, max);
|
|
35387
|
-
if (keepMeshData) {
|
|
35388
|
-
var clonePosition = position1.clone();
|
|
35389
|
-
elementNormalized && clonePosition.scale(scaleFactor);
|
|
35390
|
-
positions[j1] = clonePosition;
|
|
35391
|
-
}
|
|
35392
|
-
}
|
|
35393
|
-
}
|
|
35394
|
-
if (elementNormalized) {
|
|
35395
|
-
min.scale(scaleFactor);
|
|
35396
|
-
max.scale(scaleFactor);
|
|
35397
|
-
}
|
|
35398
|
-
} else if (attribute === "JOINTS_0" && keepMeshData) {
|
|
35399
|
-
var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
35400
|
-
var stride3 = vertices.length / accessorCount;
|
|
35401
|
-
for(var j2 = 0; j2 < accessorCount; j2++){
|
|
35402
|
-
var offset2 = baseOffset2 + j2 * stride3;
|
|
35403
|
-
var boneIndex = new Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
|
|
35404
|
-
elementNormalized && boneIndex.scale(scaleFactor);
|
|
35405
|
-
boneIndices[j2] = boneIndex;
|
|
35406
|
-
}
|
|
35407
|
-
} else if (attribute === "WEIGHTS_0" && keepMeshData) {
|
|
35408
|
-
var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
|
|
35409
|
-
var stride4 = vertices.length / accessorCount;
|
|
35410
|
-
for(var j3 = 0; j3 < accessorCount; j3++){
|
|
35411
|
-
var offset3 = baseOffset3 + j3 * stride4;
|
|
35412
|
-
var boneWeight = new Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
|
|
35413
|
-
elementNormalized && boneWeight.scale(scaleFactor);
|
|
35414
|
-
boneWeights[j3] = boneWeight;
|
|
35415
|
-
}
|
|
35416
|
-
}
|
|
35417
|
-
}
|
|
35418
|
-
mesh.setVertexElements(vertexElements);
|
|
35419
|
-
// Indices
|
|
35420
|
-
if (indices !== undefined) {
|
|
35421
|
-
var indexAccessor = gltf.accessors[indices];
|
|
35422
|
-
var accessorBuffer1 = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor);
|
|
35423
|
-
mesh.setIndices(accessorBuffer1.data);
|
|
35424
|
-
mesh.addSubMesh(0, indexAccessor.count, mode);
|
|
35425
|
-
meshRestoreInfo.indexBuffer = accessorBuffer1.restoreInfo;
|
|
35426
|
-
} else {
|
|
35427
|
-
mesh.addSubMesh(0, vertexCount, mode);
|
|
35428
|
-
}
|
|
35429
|
-
// BlendShapes
|
|
35430
|
-
targets && GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData);
|
|
35431
|
-
mesh.uploadData(!keepMeshData);
|
|
35432
|
-
//@ts-ignore
|
|
35433
|
-
mesh._positions = positions;
|
|
35434
|
-
//@ts-ignore
|
|
35435
|
-
mesh._boneIndices = boneIndices;
|
|
35436
|
-
//@ts-ignore
|
|
35437
|
-
mesh._boneWeights = boneWeights;
|
|
35438
|
-
return Promise.resolve(mesh);
|
|
35555
|
+
mesh.addSubMesh(0, vertexCount, mode);
|
|
35556
|
+
}
|
|
35557
|
+
// BlendShapes
|
|
35558
|
+
if (targets) {
|
|
35559
|
+
promises.push(GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData));
|
|
35560
|
+
}
|
|
35561
|
+
return Promise.all(promises).then(function() {
|
|
35562
|
+
mesh.uploadData(!keepMeshData);
|
|
35563
|
+
//@ts-ignore
|
|
35564
|
+
mesh._positions = positions;
|
|
35565
|
+
//@ts-ignore
|
|
35566
|
+
mesh._boneIndices = boneIndices;
|
|
35567
|
+
//@ts-ignore
|
|
35568
|
+
mesh._boneWeights = boneWeights;
|
|
35569
|
+
return Promise.resolve(mesh);
|
|
35570
|
+
});
|
|
35571
|
+
});
|
|
35439
35572
|
};
|
|
35440
35573
|
/**
|
|
35441
35574
|
* @internal
|
|
35442
35575
|
*/ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
|
|
35443
|
-
var
|
|
35444
|
-
for(var i = 0, n = glTFTargets.length; i < n; i++){
|
|
35576
|
+
var _loop = function _loop(i, n) {
|
|
35445
35577
|
var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
|
|
35446
|
-
var
|
|
35447
|
-
|
|
35448
|
-
|
|
35449
|
-
|
|
35450
|
-
|
|
35451
|
-
|
|
35452
|
-
|
|
35453
|
-
|
|
35454
|
-
|
|
35455
|
-
|
|
35456
|
-
|
|
35578
|
+
var promise = Promise.all([
|
|
35579
|
+
getBlendShapeData("POSITION", i),
|
|
35580
|
+
getBlendShapeData("NORMAL", i),
|
|
35581
|
+
getBlendShapeData("TANGENT", i)
|
|
35582
|
+
]).then(function(infos) {
|
|
35583
|
+
var deltaPosBufferInfo = infos[0];
|
|
35584
|
+
var deltaNorBufferInfo = infos[1];
|
|
35585
|
+
var deltaTanBufferInfo = infos[2];
|
|
35586
|
+
var deltaPositions = deltaPosBufferInfo.data ? GLTFUtils.floatBufferToVector3Array(deltaPosBufferInfo.data) : null;
|
|
35587
|
+
var deltaNormals = (deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) : null;
|
|
35588
|
+
var deltaTangents = (deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) : null;
|
|
35589
|
+
var blendShape = new BlendShape(name);
|
|
35590
|
+
blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
|
|
35591
|
+
mesh.addBlendShape(blendShape);
|
|
35592
|
+
meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, deltaPosBufferInfo.restoreInfo, deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.restoreInfo, deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.restoreInfo));
|
|
35593
|
+
});
|
|
35594
|
+
promises.push(promise);
|
|
35595
|
+
};
|
|
35596
|
+
var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
|
|
35597
|
+
var promises = new Array();
|
|
35598
|
+
for(var i = 0, n = glTFTargets.length; i < n; i++)_loop(i);
|
|
35599
|
+
return Promise.all(promises);
|
|
35457
35600
|
};
|
|
35458
35601
|
return GLTFMeshParser;
|
|
35459
35602
|
}(GLTFParser);
|
|
@@ -35603,52 +35746,58 @@
|
|
|
35603
35746
|
_inherits(GLTFSkinParser, GLTFParser);
|
|
35604
35747
|
var _proto = GLTFSkinParser.prototype;
|
|
35605
35748
|
_proto.parse = function parse(context) {
|
|
35606
|
-
var
|
|
35607
|
-
context.buffers;
|
|
35608
|
-
var entities = glTFResource.entities;
|
|
35609
|
-
var gltfSkins = glTF.skins;
|
|
35610
|
-
if (!gltfSkins) return;
|
|
35611
|
-
var count = gltfSkins.length;
|
|
35612
|
-
var skins = new Array(count);
|
|
35613
|
-
for(var i = 0; i < count; i++){
|
|
35749
|
+
var _loop = function _loop(i) {
|
|
35614
35750
|
var _gltfSkins_i = gltfSkins[i], inverseBindMatrices = _gltfSkins_i.inverseBindMatrices, skeleton = _gltfSkins_i.skeleton, joints = _gltfSkins_i.joints, _gltfSkins_i_name = _gltfSkins_i.name, name = _gltfSkins_i_name === void 0 ? "SKIN_" + i : _gltfSkins_i_name;
|
|
35615
35751
|
var jointCount = joints.length;
|
|
35616
35752
|
var skin = new Skin(name);
|
|
35617
35753
|
skin.inverseBindMatrices.length = jointCount;
|
|
35618
35754
|
// parse IBM
|
|
35619
35755
|
var accessor = glTF.accessors[inverseBindMatrices];
|
|
35620
|
-
var
|
|
35621
|
-
|
|
35622
|
-
var
|
|
35623
|
-
|
|
35624
|
-
|
|
35625
|
-
|
|
35626
|
-
|
|
35627
|
-
|
|
35628
|
-
|
|
35629
|
-
|
|
35630
|
-
|
|
35631
|
-
|
|
35632
|
-
|
|
35633
|
-
|
|
35634
|
-
|
|
35756
|
+
var promise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
|
|
35757
|
+
var buffer = bufferInfo.data;
|
|
35758
|
+
for(var _$i = 0; _$i < jointCount; _$i++){
|
|
35759
|
+
var inverseBindMatrix = new Matrix();
|
|
35760
|
+
inverseBindMatrix.copyFromArray(buffer, _$i * 16);
|
|
35761
|
+
skin.inverseBindMatrices[_$i] = inverseBindMatrix;
|
|
35762
|
+
// get joints
|
|
35763
|
+
for(var i1 = 0; i1 < jointCount; i1++){
|
|
35764
|
+
var jointIndex = joints[i1];
|
|
35765
|
+
var jointName = entities[jointIndex].name;
|
|
35766
|
+
skin.joints[i1] = jointName;
|
|
35767
|
+
// @todo Temporary solution, but it can alleviate the current BUG, and the skinning data mechanism of SkinnedMeshRenderer will be completely refactored in the future
|
|
35768
|
+
for(var j = entities.length - 1; j >= 0; j--){
|
|
35769
|
+
if (jointIndex !== j && entities[j].name === jointName) {
|
|
35770
|
+
entities[j].name = jointName + "_" + j;
|
|
35771
|
+
}
|
|
35772
|
+
}
|
|
35773
|
+
}
|
|
35774
|
+
// get skeleton
|
|
35775
|
+
if (skeleton !== undefined) {
|
|
35776
|
+
skin.skeleton = entities[skeleton].name;
|
|
35777
|
+
} else {
|
|
35778
|
+
var rootBone = _this._findSkeletonRootBone(joints, entities);
|
|
35779
|
+
if (rootBone) {
|
|
35780
|
+
skin.skeleton = rootBone.name;
|
|
35781
|
+
} else {
|
|
35782
|
+
throw "Failed to find skeleton root bone.";
|
|
35783
|
+
}
|
|
35635
35784
|
}
|
|
35636
35785
|
}
|
|
35637
|
-
|
|
35638
|
-
|
|
35639
|
-
|
|
35640
|
-
|
|
35641
|
-
|
|
35642
|
-
|
|
35643
|
-
|
|
35644
|
-
|
|
35645
|
-
|
|
35646
|
-
|
|
35647
|
-
|
|
35648
|
-
|
|
35649
|
-
|
|
35650
|
-
|
|
35651
|
-
|
|
35786
|
+
return skin;
|
|
35787
|
+
});
|
|
35788
|
+
promises.push(promise);
|
|
35789
|
+
};
|
|
35790
|
+
var _this = this;
|
|
35791
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
35792
|
+
var entities = glTFResource.entities;
|
|
35793
|
+
var gltfSkins = glTF.skins;
|
|
35794
|
+
if (!gltfSkins) return;
|
|
35795
|
+
var count = gltfSkins.length;
|
|
35796
|
+
var promises = new Array();
|
|
35797
|
+
for(var i = 0; i < count; i++)_loop(i);
|
|
35798
|
+
return AssetPromise.all(promises).then(function(skins) {
|
|
35799
|
+
glTFResource.skins = skins;
|
|
35800
|
+
});
|
|
35652
35801
|
};
|
|
35653
35802
|
_proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
|
|
35654
35803
|
var paths = {};
|
|
@@ -35688,13 +35837,14 @@
|
|
|
35688
35837
|
var _proto = GLTFTextureParser.prototype;
|
|
35689
35838
|
_proto.parse = function parse(context) {
|
|
35690
35839
|
var _this = this;
|
|
35691
|
-
var glTFResource = context.glTFResource, glTF = context.glTF
|
|
35840
|
+
var glTFResource = context.glTFResource, glTF = context.glTF;
|
|
35692
35841
|
var engine = glTFResource.engine, url = glTFResource.url;
|
|
35693
35842
|
if (glTF.textures) {
|
|
35694
35843
|
var texturesPromiseInfo = context.texturesPromiseInfo;
|
|
35695
35844
|
AssetPromise.all(glTF.textures.map(function(param, index) {
|
|
35696
35845
|
var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
|
|
35697
35846
|
var _glTF_images_source = glTF.images[source], uri = _glTF_images_source.uri, bufferViewIndex = _glTF_images_source.bufferView, mimeType = _glTF_images_source.mimeType, imageName = _glTF_images_source.name;
|
|
35847
|
+
var samplerInfo = sampler !== undefined && _this._getSamplerInfo(glTF.samplers[sampler]);
|
|
35698
35848
|
if (uri) {
|
|
35699
35849
|
// TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
|
|
35700
35850
|
var index1 = uri.lastIndexOf(".");
|
|
@@ -35702,31 +35852,36 @@
|
|
|
35702
35852
|
var type = ext.startsWith("ktx") ? exports.AssetType.KTX : exports.AssetType.Texture2D;
|
|
35703
35853
|
return engine.resourceManager.load({
|
|
35704
35854
|
url: Utils.resolveAbsoluteUrl(url, uri),
|
|
35705
|
-
type: type
|
|
35855
|
+
type: type,
|
|
35856
|
+
params: {
|
|
35857
|
+
mipmap: samplerInfo == null ? void 0 : samplerInfo.mipmap
|
|
35858
|
+
}
|
|
35706
35859
|
}).then(function(texture) {
|
|
35707
35860
|
if (!texture.name) {
|
|
35708
35861
|
texture.name = textureName || imageName || "texture_" + index1;
|
|
35709
35862
|
}
|
|
35710
35863
|
if (sampler !== undefined) {
|
|
35711
|
-
_this._parseSampler(texture,
|
|
35864
|
+
_this._parseSampler(texture, samplerInfo);
|
|
35712
35865
|
}
|
|
35713
35866
|
return texture;
|
|
35714
35867
|
});
|
|
35715
35868
|
} else {
|
|
35716
35869
|
var bufferView = glTF.bufferViews[bufferViewIndex];
|
|
35717
|
-
|
|
35718
|
-
|
|
35719
|
-
|
|
35720
|
-
|
|
35721
|
-
|
|
35722
|
-
|
|
35723
|
-
|
|
35724
|
-
|
|
35725
|
-
|
|
35726
|
-
|
|
35727
|
-
|
|
35728
|
-
|
|
35729
|
-
|
|
35870
|
+
return context.getBuffers().then(function(buffers) {
|
|
35871
|
+
var buffer = buffers[bufferView.buffer];
|
|
35872
|
+
var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
|
|
35873
|
+
return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
|
|
35874
|
+
var texture = new Texture2D(engine, image.width, image.height, undefined, samplerInfo == null ? void 0 : samplerInfo.mipmap);
|
|
35875
|
+
texture.setImageSource(image);
|
|
35876
|
+
texture.generateMipmaps();
|
|
35877
|
+
texture.name = textureName || imageName || "texture_" + index;
|
|
35878
|
+
if (sampler !== undefined) {
|
|
35879
|
+
_this._parseSampler(texture, samplerInfo);
|
|
35880
|
+
}
|
|
35881
|
+
var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
|
|
35882
|
+
context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
|
|
35883
|
+
return texture;
|
|
35884
|
+
});
|
|
35730
35885
|
});
|
|
35731
35886
|
}
|
|
35732
35887
|
})).then(function(textures) {
|
|
@@ -35736,22 +35891,39 @@
|
|
|
35736
35891
|
return texturesPromiseInfo.promise;
|
|
35737
35892
|
}
|
|
35738
35893
|
};
|
|
35739
|
-
_proto.
|
|
35740
|
-
var
|
|
35741
|
-
|
|
35894
|
+
_proto._getSamplerInfo = function _getSamplerInfo(sampler) {
|
|
35895
|
+
var minFilter = sampler.minFilter, magFilter = sampler.magFilter, wrapS = sampler.wrapS, wrapT = sampler.wrapT;
|
|
35896
|
+
var info = {};
|
|
35897
|
+
if (minFilter || magFilter) {
|
|
35898
|
+
info.mipmap = minFilter >= TextureMinFilter.NEAREST_MIPMAP_NEAREST;
|
|
35742
35899
|
if (magFilter === TextureMagFilter.NEAREST) {
|
|
35743
|
-
|
|
35744
|
-
} else if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
35745
|
-
texture.filterMode = exports.TextureFilterMode.Bilinear;
|
|
35900
|
+
info.filterMode = exports.TextureFilterMode.Point;
|
|
35746
35901
|
} else {
|
|
35747
|
-
|
|
35902
|
+
if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
|
|
35903
|
+
info.filterMode = exports.TextureFilterMode.Bilinear;
|
|
35904
|
+
} else {
|
|
35905
|
+
info.filterMode = exports.TextureFilterMode.Trilinear;
|
|
35906
|
+
}
|
|
35748
35907
|
}
|
|
35749
35908
|
}
|
|
35750
35909
|
if (wrapS) {
|
|
35751
|
-
|
|
35910
|
+
info.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
|
|
35752
35911
|
}
|
|
35753
35912
|
if (wrapT) {
|
|
35754
|
-
|
|
35913
|
+
info.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
|
|
35914
|
+
}
|
|
35915
|
+
return info;
|
|
35916
|
+
};
|
|
35917
|
+
_proto._parseSampler = function _parseSampler(texture, samplerInfo) {
|
|
35918
|
+
var filterMode = samplerInfo.filterMode, wrapModeU = samplerInfo.wrapModeU, wrapModeV = samplerInfo.wrapModeV;
|
|
35919
|
+
if (filterMode) {
|
|
35920
|
+
texture.filterMode = filterMode;
|
|
35921
|
+
}
|
|
35922
|
+
if (wrapModeU) {
|
|
35923
|
+
texture.wrapModeU = wrapModeU;
|
|
35924
|
+
}
|
|
35925
|
+
if (wrapModeV) {
|
|
35926
|
+
texture.wrapModeV = wrapModeV;
|
|
35755
35927
|
}
|
|
35756
35928
|
};
|
|
35757
35929
|
return GLTFTextureParser;
|
|
@@ -37805,7 +37977,7 @@
|
|
|
37805
37977
|
_this.request(item.url, _extends({}, item, {
|
|
37806
37978
|
type: "arraybuffer"
|
|
37807
37979
|
})).then(function(data) {
|
|
37808
|
-
return decode(data, resourceManager.engine);
|
|
37980
|
+
return decode(data, resourceManager.engine).then(resolve);
|
|
37809
37981
|
}).catch(reject);
|
|
37810
37982
|
});
|
|
37811
37983
|
};
|
|
@@ -37942,7 +38114,7 @@
|
|
|
37942
38114
|
};
|
|
37943
38115
|
_proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
|
|
37944
38116
|
var _this = this;
|
|
37945
|
-
var glTF = context.glTF,
|
|
38117
|
+
var glTF = context.glTF, engine = context.glTFResource.engine;
|
|
37946
38118
|
var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
|
|
37947
38119
|
var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
|
|
37948
38120
|
var attributeMap = {};
|
|
@@ -37964,21 +38136,23 @@
|
|
|
37964
38136
|
useUniqueIDs: true,
|
|
37965
38137
|
indexType: indexType
|
|
37966
38138
|
};
|
|
37967
|
-
|
|
37968
|
-
|
|
37969
|
-
|
|
37970
|
-
|
|
37971
|
-
|
|
37972
|
-
|
|
37973
|
-
|
|
38139
|
+
return context.getBuffers().then(function(buffers) {
|
|
38140
|
+
var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
|
|
38141
|
+
return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
|
|
38142
|
+
var mesh = new ModelMesh(engine, glTFMesh.name);
|
|
38143
|
+
return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
|
|
38144
|
+
for(var j = 0; j < decodedGeometry.attributes.length; j++){
|
|
38145
|
+
if (decodedGeometry.attributes[j].name === attributeSemantic) {
|
|
38146
|
+
return decodedGeometry.attributes[j].array;
|
|
38147
|
+
}
|
|
37974
38148
|
}
|
|
37975
|
-
|
|
37976
|
-
|
|
37977
|
-
|
|
37978
|
-
|
|
37979
|
-
|
|
37980
|
-
|
|
37981
|
-
}
|
|
38149
|
+
return null;
|
|
38150
|
+
}, function(attributeSemantic, shapeIndex) {
|
|
38151
|
+
throw "BlendShape animation is not supported when using draco.";
|
|
38152
|
+
}, function() {
|
|
38153
|
+
return decodedGeometry.index.array;
|
|
38154
|
+
}, context.keepMeshData);
|
|
38155
|
+
});
|
|
37982
38156
|
});
|
|
37983
38157
|
};
|
|
37984
38158
|
_proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
|
|
@@ -38303,7 +38477,7 @@
|
|
|
38303
38477
|
], GALACEAN_animation_event);
|
|
38304
38478
|
|
|
38305
38479
|
//@ts-ignore
|
|
38306
|
-
var version = "1.0.0-beta.
|
|
38480
|
+
var version = "1.0.0-beta.17";
|
|
38307
38481
|
console.log("Galacean engine version: " + version);
|
|
38308
38482
|
for(var key in CoreObjects){
|
|
38309
38483
|
Loader.registerClass(key, CoreObjects[key]);
|