@galacean/effects-plugin-model 2.1.0-alpha.1 → 2.1.0-alpha.10

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/douyin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as EFFECTS from '@galacean/effects/douyin';
2
- import { math, Transform, PLAYER_OPTIONS_ENV_EDITOR, spec, glContext, Texture, TextureSourceType, RenderPassAttachmentStorageType, Material, Mesh, Geometry, GLSLVersion, addItem, removeItem, ShaderFactory, effectsClass, RendererComponent, Behaviour, HitTestType, AnimationClip, RenderPass, TextureLoadAction, DestroyOptions, RenderPassDestroyAttachmentType, Player, Renderer, getDefaultTextureFactory, loadImage, generateGUID, VFXItem, AbstractPlugin, glType2VertexFormatType, Downloader, getStandardJSON, isObject, registerPlugin, logger } from '@galacean/effects/douyin';
2
+ import { math, spec, Transform, PLAYER_OPTIONS_ENV_EDITOR, glContext, Texture, TextureSourceType, RenderPassAttachmentStorageType, Material, Mesh, Geometry, GLSLVersion, addItem, removeItem, ShaderFactory, effectsClass, RendererComponent, Behaviour, HitTestType, AnimationClip, RenderPass, TextureLoadAction, DestroyOptions, RenderPassDestroyAttachmentType, Player, Renderer, getDefaultTextureFactory, loadImage, generateGUID, VFXItem, AbstractPlugin, glType2VertexFormatType, Downloader, getStandardJSON, isObject, registerPlugin, logger } from '@galacean/effects/douyin';
3
3
 
4
4
  /**
5
5
  * Model 插件元素类型
@@ -257,8 +257,8 @@ var PShadowType;
257
257
  PShadowType[PShadowType["variance"] = 2] = "variance";
258
258
  PShadowType[PShadowType["expVariance"] = 3] = "expVariance";
259
259
  })(PShadowType || (PShadowType = {}));
260
- var PBRShaderGUID = "pbr00000000000000000000000000000";
261
- var UnlitShaderGUID = "unlit000000000000000000000000000";
260
+ var PBRShaderGUID = spec.BuiltinObjectGUID.PBRShader;
261
+ var UnlitShaderGUID = spec.BuiltinObjectGUID.UnlitShader;
262
262
  /**
263
263
  * 插件变换类
264
264
  */ var PTransform = /*#__PURE__*/ function() {
@@ -1480,144 +1480,6 @@ var PAnimPathType;
1480
1480
  PAnimPathType[PAnimPathType["scale"] = 2] = "scale";
1481
1481
  PAnimPathType[PAnimPathType["weights"] = 3] = "weights";
1482
1482
  })(PAnimPathType || (PAnimPathType = {}));
1483
- /**
1484
- * 动画轨道类
1485
- */ var PAnimTrack = /*#__PURE__*/ function() {
1486
- function PAnimTrack(options) {
1487
- /**
1488
- * 路径类型
1489
- */ this.path = 0;
1490
- /**
1491
- * 插值类型
1492
- */ this.interp = 0;
1493
- var node = options.node, input = options.input, output = options.output, path = options.path, interpolation = options.interpolation;
1494
- this.node = node;
1495
- this.timeArray = input;
1496
- this.dataArray = output;
1497
- //
1498
- if (path === "translation") {
1499
- this.path = 0;
1500
- this.component = 3;
1501
- } else if (path === "rotation") {
1502
- this.path = 1;
1503
- this.component = 4;
1504
- } else if (path === "scale") {
1505
- this.path = 2;
1506
- this.component = 3;
1507
- } else if (path === "weights") {
1508
- this.path = 3;
1509
- this.component = this.dataArray.length / this.timeArray.length;
1510
- // special checker for weights animation
1511
- if (this.component <= 0) {
1512
- console.error("Invalid weights component: " + this.timeArray.length + ", " + this.component + ", " + this.dataArray.length + ".");
1513
- } else if (this.timeArray.length * this.component != this.dataArray.length) {
1514
- console.error("Invalid weights array length: " + this.timeArray.length + ", " + this.component + ", " + this.dataArray.length + ".");
1515
- }
1516
- } else {
1517
- // should never happened
1518
- console.error("Invalid path status: " + path + ".");
1519
- }
1520
- if (this.timeArray.length * this.component > this.dataArray.length) {
1521
- throw new Error("Data length mismatch: " + this.timeArray.length + ", " + this.component + ", " + this.dataArray.length + ".");
1522
- }
1523
- if (interpolation === "LINEAR") {
1524
- this.interp = 0;
1525
- } else if (interpolation === "STEP") {
1526
- this.interp = 1;
1527
- } else {
1528
- this.interp = 2;
1529
- }
1530
- this.sampler = createAnimationSampler(this.getInterpInfo(), this.timeArray, this.dataArray, this.component, this.getPathInfo());
1531
- }
1532
- var _proto = PAnimTrack.prototype;
1533
- /**
1534
- * 销毁
1535
- */ _proto.dispose = function dispose() {
1536
- var _this_sampler;
1537
- // @ts-expect-error
1538
- this.timeArray = undefined;
1539
- // @ts-expect-error
1540
- this.dataArray = undefined;
1541
- (_this_sampler = this.sampler) == null ? void 0 : _this_sampler.dispose();
1542
- this.sampler = undefined;
1543
- };
1544
- /**
1545
- * 更新节点动画数据
1546
- * @param time - 当前播放时间
1547
- * @param treeItem - 节点树元素
1548
- * @param sceneManager - 3D 场景管理器
1549
- */ _proto.tick = function tick(time, treeItem, sceneManager) {
1550
- var _treeComponent_content;
1551
- var treeComponent = treeItem.getComponent(ModelTreeComponent);
1552
- var node = treeComponent == null ? void 0 : (_treeComponent_content = treeComponent.content) == null ? void 0 : _treeComponent_content.getNodeById(this.node);
1553
- if (this.sampler !== undefined && node !== undefined) {
1554
- var result = this.sampler.evaluate(time);
1555
- switch(this.path){
1556
- case 0:
1557
- node.transform.setPosition(result[0], result[1], result[2]);
1558
- break;
1559
- case 1:
1560
- node.transform.setQuaternion(result[0], result[1], result[2], result[3]);
1561
- break;
1562
- case 2:
1563
- node.transform.setScale(result[0], result[1], result[2]);
1564
- break;
1565
- case 3:
1566
- {
1567
- /**
1568
- * 先生成Mesh的父节点id,然后通过id查询Mesh对象
1569
- * 最后更新Mesh对象权重数据
1570
- */ var parentId = this.genParentId(treeItem.id, this.node);
1571
- var mesh = sceneManager == null ? void 0 : sceneManager.queryMesh(parentId);
1572
- if (mesh !== undefined) {
1573
- mesh.updateMorphWeights(result);
1574
- }
1575
- }
1576
- break;
1577
- }
1578
- } else {
1579
- if (this.sampler !== undefined) {
1580
- console.error("AnimTrack: error", this.sampler, node);
1581
- }
1582
- }
1583
- };
1584
- /**
1585
- * 获取动画结束时间
1586
- * @returns
1587
- */ _proto.getEndTime = function getEndTime() {
1588
- var index = this.timeArray.length - 1;
1589
- return this.timeArray[index];
1590
- };
1591
- /**
1592
- * 生成 Mesh 元素的父节点
1593
- *
1594
- * @param parentId - 父节点 id 名称
1595
- * @param nodeIndex - Mesh 节点索引
1596
- *
1597
- * @returns 生成的 Mesh 节点名称
1598
- */ _proto.genParentId = function genParentId(parentId, nodeIndex) {
1599
- return parentId + "^" + nodeIndex;
1600
- };
1601
- _proto.getPathInfo = function getPathInfo() {
1602
- if (this.path === 2) {
1603
- return "scale";
1604
- } else if (this.path === 1) {
1605
- return "rotation";
1606
- } else {
1607
- return "translation";
1608
- }
1609
- };
1610
- _proto.getInterpInfo = function getInterpInfo() {
1611
- if (this.interp === 2) {
1612
- return "CUBICSPLINE";
1613
- } else if (this.interp === 1) {
1614
- return "STEP";
1615
- } else {
1616
- return "LINEAR";
1617
- }
1618
- };
1619
- return PAnimTrack;
1620
- }();
1621
1483
  /**
1622
1484
  * 动画纹理类
1623
1485
  */ var PAnimTexture = /*#__PURE__*/ function() {
@@ -1704,148 +1566,6 @@ var PAnimPathType;
1704
1566
  };
1705
1567
  return PAnimTexture;
1706
1568
  }();
1707
- /**
1708
- * 动画类,负责动画数据创建、更新和销毁
1709
- */ var PAnimation = /*#__PURE__*/ function(PObject) {
1710
- _inherits(PAnimation, PObject);
1711
- function PAnimation() {
1712
- var _this;
1713
- _this = PObject.apply(this, arguments) || this;
1714
- _this.time = 0;
1715
- _this.duration = 0;
1716
- _this.tracks = [];
1717
- return _this;
1718
- }
1719
- var _proto = PAnimation.prototype;
1720
- /**
1721
- * 创建动画对象
1722
- * @param options - 动画参数
1723
- */ _proto.create = function create(options) {
1724
- var _this = this;
1725
- var _options_name;
1726
- this.name = this.genName((_options_name = options.name) != null ? _options_name : "Unnamed animation");
1727
- this.type = PObjectType.animation;
1728
- //
1729
- this.time = 0;
1730
- this.duration = 0;
1731
- //
1732
- this.tracks = [];
1733
- options.tracks.forEach(function(inTrack) {
1734
- var track = new PAnimTrack(inTrack);
1735
- _this.tracks.push(track);
1736
- _this.duration = Math.max(_this.duration, track.getEndTime());
1737
- });
1738
- };
1739
- /**
1740
- * 动画更新
1741
- * @param time - 当前时间
1742
- * @param treeItem - 场景树元素
1743
- * @param sceneManager - 3D 场景管理器
1744
- */ _proto.tick = function tick(time, treeItem, sceneManager) {
1745
- this.time = time;
1746
- // TODO: 这里时间事件定义不明确,先兼容原先实现
1747
- var newTime = this.time % this.duration;
1748
- this.tracks.forEach(function(track) {
1749
- track.tick(newTime, treeItem, sceneManager);
1750
- });
1751
- };
1752
- /**
1753
- * 销毁
1754
- */ _proto.dispose = function dispose() {
1755
- this.tracks.forEach(function(track) {
1756
- track.dispose();
1757
- });
1758
- this.tracks = [];
1759
- };
1760
- return PAnimation;
1761
- }(PObject);
1762
- /**
1763
- * 动画管理类,负责管理动画对象
1764
- */ var PAnimationManager = /*#__PURE__*/ function(PObject) {
1765
- _inherits(PAnimationManager, PObject);
1766
- function PAnimationManager(treeOptions, ownerItem) {
1767
- var _this;
1768
- _this = PObject.call(this) || this;
1769
- _this.animation = 0;
1770
- _this.speed = 0;
1771
- _this.delay = 0;
1772
- _this.time = 0;
1773
- _this.animations = [];
1774
- var _ownerItem_name;
1775
- _this.name = _this.genName((_ownerItem_name = ownerItem.name) != null ? _ownerItem_name : "Unnamed tree");
1776
- _this.type = PObjectType.animationManager;
1777
- //
1778
- _this.ownerItem = ownerItem;
1779
- var _treeOptions_animation;
1780
- _this.animation = (_treeOptions_animation = treeOptions.animation) != null ? _treeOptions_animation : -1;
1781
- _this.speed = 1.0;
1782
- var _ownerItem_start;
1783
- _this.delay = (_ownerItem_start = ownerItem.start) != null ? _ownerItem_start : 0;
1784
- _this.animations = [];
1785
- if (treeOptions.animations !== undefined) {
1786
- treeOptions.animations.forEach(function(animOpts) {
1787
- var anim = _this.createAnimation(animOpts);
1788
- _this.animations.push(anim);
1789
- });
1790
- }
1791
- return _this;
1792
- }
1793
- var _proto = PAnimationManager.prototype;
1794
- /**
1795
- * 设置场景管理器
1796
- * @param sceneManager - 场景管理器
1797
- */ _proto.setSceneManager = function setSceneManager(sceneManager) {
1798
- this.sceneManager = sceneManager;
1799
- };
1800
- /**
1801
- * 创建动画对象
1802
- * @param animationOpts - 动画参数
1803
- * @returns 动画对象
1804
- */ _proto.createAnimation = function createAnimation(animationOpts) {
1805
- var animation = new PAnimation();
1806
- animation.create(animationOpts);
1807
- return animation;
1808
- };
1809
- /**
1810
- * 动画更新
1811
- * @param deltaSeconds - 更新间隔
1812
- */ _proto.tick = function tick(deltaSeconds) {
1813
- var _this = this;
1814
- var newDeltaSeconds = deltaSeconds * this.speed * 0.001;
1815
- this.time += newDeltaSeconds;
1816
- // TODO: 需要合并到TreeItem中,通过lifetime进行计算
1817
- var itemTime = this.time - this.delay;
1818
- if (itemTime >= 0) {
1819
- if (this.animation >= 0 && this.animation < this.animations.length) {
1820
- var anim = this.animations[this.animation];
1821
- anim.tick(itemTime, this.ownerItem, this.sceneManager);
1822
- } else if (this.animation == -88888888) {
1823
- this.animations.forEach(function(anim) {
1824
- anim.tick(itemTime, _this.ownerItem, _this.sceneManager);
1825
- });
1826
- }
1827
- }
1828
- };
1829
- /**
1830
- * 销毁
1831
- */ _proto.dispose = function dispose() {
1832
- // @ts-expect-error
1833
- this.ownerItem = null;
1834
- this.animations.forEach(function(anim) {
1835
- anim.dispose();
1836
- });
1837
- this.animations = [];
1838
- // @ts-expect-error
1839
- this.sceneManager = null;
1840
- };
1841
- /**
1842
- * 获取场景树元素
1843
- * @returns
1844
- */ _proto.getTreeItem = function getTreeItem() {
1845
- return this.ownerItem;
1846
- };
1847
- return PAnimationManager;
1848
- }(PObject);
1849
1569
 
1850
1570
  var deg2rad = Math.PI / 180;
1851
1571
  /**
@@ -2142,6 +1862,9 @@ var deg2rad = Math.PI / 180;
2142
1862
  * 类型
2143
1863
  */ _this.lightType = PLightType.ambient;
2144
1864
  _this.padding = new Vector2(0, 0);
1865
+ /**
1866
+ * 是否跟随相机
1867
+ */ _this.followCamera = false;
2145
1868
  _this.name = name;
2146
1869
  _this.type = PObjectType.light;
2147
1870
  _this.visible = false;
@@ -2154,6 +1877,8 @@ var deg2rad = Math.PI / 180;
2154
1877
  var color = data.color;
2155
1878
  _this.color = new Vector3(color.r, color.g, color.b);
2156
1879
  _this.intensity = data.intensity;
1880
+ var _data_followCamera;
1881
+ _this.followCamera = (_data_followCamera = data.followCamera) != null ? _data_followCamera : false;
2157
1882
  if (data.lightType === spec.LightType.point) {
2158
1883
  _this.lightType = PLightType.point;
2159
1884
  var _data_range;
@@ -3163,6 +2888,8 @@ function _assert_this_initialized(self) {
3163
2888
  return "DEBUG_OCCLUSION";
3164
2889
  case spec.RenderMode3D.emissive:
3165
2890
  return "DEBUG_EMISSIVE";
2891
+ case spec.RenderMode3D.diffuse:
2892
+ return "DEBUG_DIFFUSE";
3166
2893
  }
3167
2894
  };
3168
2895
  _proto.updateUniformsByAnimation = function updateUniformsByAnimation(worldMatrix, normalMatrix) {
@@ -3208,16 +2935,23 @@ function _assert_this_initialized(self) {
3208
2935
  material.setVector3("_Camera", sceneStates.cameraPosition);
3209
2936
  //
3210
2937
  if (!this.isUnlitMaterial()) {
3211
- var maxLightCount = sceneStates.maxLightCount, lightList = sceneStates.lightList;
2938
+ var maxLightCount = sceneStates.maxLightCount, lightList = sceneStates.lightList, inverseViewMatrix = sceneStates.inverseViewMatrix;
3212
2939
  for(var i = 0; i < maxLightCount; i++){
3213
2940
  if (i < lightList.length) {
3214
2941
  var light = lightList[i];
3215
2942
  var intensity = light.visible ? light.intensity : 0;
3216
- material.setVector3("_Lights[" + i + "].direction", light.getWorldDirection());
2943
+ if (light.followCamera) {
2944
+ var newDirection = inverseViewMatrix.transformNormal(light.getWorldDirection(), new Vector3());
2945
+ var newPosition = inverseViewMatrix.transformPoint(light.getWorldPosition(), new Vector3());
2946
+ material.setVector3("_Lights[" + i + "].direction", newDirection);
2947
+ material.setVector3("_Lights[" + i + "].position", newPosition);
2948
+ } else {
2949
+ material.setVector3("_Lights[" + i + "].direction", light.getWorldDirection());
2950
+ material.setVector3("_Lights[" + i + "].position", light.getWorldPosition());
2951
+ }
3217
2952
  material.setFloat("_Lights[" + i + "].range", light.range);
3218
2953
  material.setVector3("_Lights[" + i + "].color", light.color);
3219
2954
  material.setFloat("_Lights[" + i + "].intensity", intensity);
3220
- material.setVector3("_Lights[" + i + "].position", light.getWorldPosition());
3221
2955
  material.setFloat("_Lights[" + i + "].innerConeCos", Math.cos(light.innerConeAngle));
3222
2956
  material.setFloat("_Lights[" + i + "].outerConeCos", Math.cos(light.outerConeAngle));
3223
2957
  material.setInt("_Lights[" + i + "].type", light.lightType);
@@ -3481,15 +3215,6 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
3481
3215
  _proto.isHide = function isHide() {
3482
3216
  return this.data.hide === true;
3483
3217
  };
3484
- _proto.getParentNode = function getParentNode() {
3485
- var _this_parentItem;
3486
- var nodeIndex = this.getParentIndex();
3487
- var parentTree = (_this_parentItem = this.parentItem) == null ? void 0 : _this_parentItem.getComponent(ModelTreeComponent);
3488
- if (parentTree !== undefined && nodeIndex >= 0) {
3489
- return parentTree.content.getNodeById(nodeIndex);
3490
- }
3491
- return undefined;
3492
- };
3493
3218
  _proto.getParentIndex = function getParentIndex() {
3494
3219
  return -1;
3495
3220
  };
@@ -3762,6 +3487,7 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
3762
3487
  camera: camera,
3763
3488
  cameraPosition: camera.getEye(),
3764
3489
  viewMatrix: viewMatrix,
3490
+ inverseViewMatrix: viewMatrix.clone().invert(),
3765
3491
  projectionMatrix: projectionMatrix,
3766
3492
  viewProjectionMatrix: viewProjectionMatrix,
3767
3493
  winSize: camera.getSize(),
@@ -3926,7 +3652,7 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
3926
3652
 
3927
3653
  var primitiveVert = "precision highp float;\n#define FEATURES\n#include <animation.vert.glsl>\nattribute vec4 aPos;varying vec3 v_Position;\n#ifdef HAS_NORMALS\nattribute vec4 aNormal;\n#endif\n#ifdef HAS_TANGENTS\nattribute vec4 aTangent;\n#endif\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nvarying mat3 v_TBN;\n#else\nvarying vec3 v_Normal;\n#endif\n#endif\n#ifdef HAS_UV_SET1\nattribute vec2 aUV;\n#endif\n#ifdef HAS_UV_SET2\nattribute vec2 aUV2;\n#endif\nvarying vec2 v_UVCoord1;\n#ifdef HAS_UV_SET2\nvarying vec2 v_UVCoord2;\n#endif\n#ifdef HAS_VERTEX_COLOR_VEC3\nattribute vec3 aColor;varying vec3 v_Color;\n#endif\n#ifdef HAS_VERTEX_COLOR_VEC4\nattribute vec4 aColor;varying vec4 v_Color;\n#endif\nuniform mat4 effects_MatrixVP;uniform mat4 effects_ObjectToWorld;uniform mat4 _NormalMatrix;\n#ifdef EDITOR_TRANSFORM\nuniform vec4 uEditorTransform;\n#endif\n#ifdef USE_SHADOW_MAPPING\nuniform mat4 _LightViewProjectionMatrix;uniform float _DeltaSceneSize;varying vec4 v_PositionLightSpace;varying vec4 v_dPositionLightSpace;\n#endif\nvec4 getPosition(){vec4 pos=vec4(aPos.xyz,1.0);\n#ifdef USE_MORPHING\npos+=getTargetPosition();\n#endif\n#ifdef USE_SKINNING\npos=getSkinningMatrix()*pos;\n#endif\nreturn pos;}\n#ifdef HAS_NORMALS\nvec4 getNormal(){vec4 normal=aNormal;\n#ifdef USE_MORPHING\nnormal+=getTargetNormal();\n#endif\n#ifdef USE_SKINNING\nnormal=getSkinningNormalMatrix()*normal;\n#endif\nreturn normalize(normal);}\n#endif\n#ifdef HAS_TANGENTS\nvec4 getTangent(){vec4 tangent=aTangent;\n#ifdef USE_MORPHING\ntangent+=getTargetTangent();\n#endif\n#ifdef USE_SKINNING\ntangent=getSkinningMatrix()*tangent;\n#endif\nreturn normalize(tangent);}\n#endif\nvoid main(){vec4 pos=effects_ObjectToWorld*getPosition();v_Position=vec3(pos.xyz)/pos.w;\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nvec4 tangent=getTangent();vec3 normalW=normalize(vec3(_NormalMatrix*vec4(getNormal().xyz,0.0)));vec3 tangentW=normalize(vec3(effects_ObjectToWorld*vec4(tangent.xyz,0.0)));vec3 bitangentW=cross(normalW,tangentW)*tangent.w;v_TBN=mat3(tangentW,bitangentW,normalW);\n#else\nv_Normal=normalize(vec3(_NormalMatrix*vec4(getNormal().xyz,0.0)));\n#endif\n#endif\nv_UVCoord1=vec2(0.0,0.0);\n#ifdef HAS_UV_SET1\nv_UVCoord1=aUV;\n#endif\n#ifdef HAS_UV_SET2\nv_UVCoord2=aUV2;\n#endif\n#if defined(HAS_VERTEX_COLOR_VEC3) || defined(HAS_VERTEX_COLOR_VEC4)\nv_Color=aColor;\n#endif\n#ifdef USE_SHADOW_MAPPING\nv_PositionLightSpace=_LightViewProjectionMatrix*pos;vec3 dpos=vec3(_DeltaSceneSize);v_dPositionLightSpace=_LightViewProjectionMatrix*(pos+vec4(dpos,0));\n#endif\ngl_Position=effects_MatrixVP*pos;\n#ifdef EDITOR_TRANSFORM\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n}";
3928
3654
 
3929
- var metallicRoughnessFrag = "\n#define FEATURES\n#extension GL_OES_standard_derivatives : enable\n#if defined(USE_TEX_LOD)\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#ifdef USE_HDR\n#extension GL_OES_texture_float : enable\n#extension GL_OES_texture_float_linear : enable\n#endif\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n#include <extensions.frag.glsl>\n#include <tone-mapping.frag.glsl>\n#include <textures.vert.glsl>\n#include <functions.frag.glsl>\n#include <shadow-common.vert.glsl>\n#include <shadow.frag.glsl>\nstruct Light{vec3 direction;float range;vec3 color;float intensity;vec3 position;float innerConeCos;float outerConeCos;int type;vec2 padding;};const int LightType_Directional=0;const int LightType_Point=1;const int LightType_Spot=2;const int LightType_Ambient=3;\n#ifdef USE_PUNCTUAL\nuniform Light _Lights[LIGHT_COUNT];\n#endif\n#if defined(MATERIAL_SPECULARGLOSSINESS) || defined(MATERIAL_METALLICROUGHNESS)\nuniform float _MetallicFactor;uniform float _RoughnessFactor;uniform vec4 _BaseColorFactor;\n#endif\n#ifdef MATERIAL_SPECULARGLOSSINESS\nuniform vec3 _SpecularFactor;uniform vec4 _DiffuseFactor;uniform float _GlossinessFactor;\n#endif\n#ifdef ALPHAMODE_MASK\nuniform float _AlphaCutoff;\n#endif\n#ifdef ADD_FOG\nuniform vec4 _FogColor;\n#ifdef LINEAR_FOG\nuniform float _FogNear;uniform float _FogFar;\n#endif\n#ifdef EXP_FOG\nuniform float _FogDensity;\n#endif\n#endif\n#ifdef PREVIEW_BORDER\nuniform vec4 uPreviewColor;\n#endif\nuniform vec3 _Camera;uniform int _MipCount;struct MaterialInfo{float perceptualRoughness;vec3 reflectance0;float alphaRoughness;vec3 diffuseColor;vec3 reflectance90;vec3 specularColor;};\n#ifdef ADD_FOG\nvec3 getMixFogColor(vec3 baseColor){vec3 distance=_Camera-v_Position;float fogAmount=0.0;\n#ifdef LINEAR_FOG\nfogAmount=smoothstep(_FogNear,_FogFar,distance[2]);\n#endif\n#ifdef EXP_FOG\n#define LOG2 1.442695\nfogAmount=1.-exp2(-_FogDensity*_FogDensity*distance[2]*distance[2]*LOG2);fogAmount=clamp(fogAmount,0.,1.);\n#endif\nvec3 mixColor=baseColor.rgb+(vec3(_FogColor)-baseColor.rgb)*fogAmount;return mixColor;}\n#endif\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 getIrradiance(vec3 norm,SHCoefficients c){float x=norm.x;float y=norm.y;float z=norm.z;float c1=0.429043;float c2=0.511664;float c3=0.743125;float c4=0.886227;float c5=0.247708;vec3 irradiance=c1*c.l22*(x*x-y*y)+c3*c.l20*(z*z)+c4*c.l00-c5*c.l20+2.0*c1*(c.l2m2*x*y+c.l21*x*z+c.l2m1*y*z)+2.0*c2*(c.l11*x+c.l1m1*y+c.l10*z);return irradiance;}\n#endif\n#ifdef USE_IBL\nvec3 getIBLContribution(MaterialInfo materialInfo,vec3 n,vec3 v){float NdotV=clamp(dot(n,v),0.0,1.0);float lod=clamp(materialInfo.perceptualRoughness*float(_MipCount),0.0,float(_MipCount));vec3 reflection=normalize(reflect(-v,n));vec2 brdfSamplePoint=clamp(vec2(NdotV,materialInfo.perceptualRoughness),vec2(0.0,0.0),vec2(1.0,1.0));vec2 brdf=texture2D(_brdfLUT,brdfSamplePoint).rg;vec4 diffuseColor=vec4(1.0,0.0,0.0,1.0);\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 irradiance=getIrradiance(n,_shCoefficients);diffuseColor=vec4(irradiance,1.0);\n#else\ndiffuseColor=textureCube(_DiffuseEnvSampler,n);\n#endif\n#ifdef USE_TEX_LOD\nvec4 specularSample=_textureCubeLodEXT(_SpecularEnvSampler,reflection,lod);\n#else\nvec4 specularSample=textureCube(_SpecularEnvSampler,reflection,lod);\n#endif\n#ifdef USE_HDR\nvec3 diffuseLight=diffuseColor.rgb;vec3 specularLight=specularSample.rgb;\n#else\nvec3 diffuseLight=SRGBtoLINEAR(diffuseColor).rgb;vec3 specularLight=SRGBtoLINEAR(specularSample).rgb;\n#endif\nvec3 diffuse=diffuseLight*materialInfo.diffuseColor;vec3 specular=specularLight*(materialInfo.specularColor*brdf.x+brdf.y);return diffuse*_IblIntensity[0]+specular*_IblIntensity[1];}\n#endif\nvec3 diffuse(MaterialInfo materialInfo){return materialInfo.diffuseColor/M_PI;}vec3 specularReflection(MaterialInfo materialInfo,AngularInfo angularInfo){return materialInfo.reflectance0+(materialInfo.reflectance90-materialInfo.reflectance0)*pow(clamp(1.0-angularInfo.VdotH,0.0,1.0),5.0);}float visibilityOcclusion(MaterialInfo materialInfo,AngularInfo angularInfo){float NdotL=angularInfo.NdotL;float NdotV=angularInfo.NdotV;float alphaRoughnessSq=materialInfo.alphaRoughness*materialInfo.alphaRoughness;float GGXV=NdotL*sqrt(NdotV*NdotV*(1.0-alphaRoughnessSq)+alphaRoughnessSq);float GGXL=NdotV*sqrt(NdotL*NdotL*(1.0-alphaRoughnessSq)+alphaRoughnessSq);float GGX=GGXV+GGXL;if(GGX>0.0){return 0.5/GGX;}return 0.0;}float microfacetDistribution(MaterialInfo materialInfo,AngularInfo angularInfo){float alphaRoughnessSq=materialInfo.alphaRoughness*materialInfo.alphaRoughness;float f=(angularInfo.NdotH*alphaRoughnessSq-angularInfo.NdotH)*angularInfo.NdotH+1.0;return alphaRoughnessSq/(M_PI*f*f);}vec3 getPointShade(vec3 pointToLight,MaterialInfo materialInfo,vec3 normal,vec3 view){AngularInfo angularInfo=getAngularInfo(pointToLight,normal,view);if(angularInfo.NdotL>0.0||angularInfo.NdotV>0.0){vec3 F=specularReflection(materialInfo,angularInfo);float Vis=visibilityOcclusion(materialInfo,angularInfo);float D=microfacetDistribution(materialInfo,angularInfo);vec3 diffuseContrib=(1.0-F)*diffuse(materialInfo);vec3 specContrib=F*Vis*D;return angularInfo.NdotL*(diffuseContrib+specContrib);}return vec3(0.0,0.0,0.0);}float getRangeAttenuation(float range,float distance){if(range<=0.0){return 1.0;}return 1.0/(pow(5.0*distance/range,2.0)+1.0);}float getSpotAttenuation(vec3 pointToLight,vec3 spotDirection,float outerConeCos,float innerConeCos){float actualCos=dot(normalize(spotDirection),normalize(-pointToLight));if(actualCos>outerConeCos){if(actualCos<innerConeCos){return smoothstep(outerConeCos,innerConeCos,actualCos);}return 1.0;}return 0.0;}vec3 applyDirectionalLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view,float shadow){vec3 pointToLight=-light.direction;vec3 shade=getPointShade(pointToLight,materialInfo,normal,view)*shadow;return light.intensity*light.color*shade;}vec3 applyPointLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view){vec3 pointToLight=light.position-v_Position;float distance=length(pointToLight);float attenuation=getRangeAttenuation(light.range,distance);vec3 shade=getPointShade(pointToLight,materialInfo,normal,view);return light.color*shade*attenuation*light.intensity;}vec3 applySpotLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view,float shadow){vec3 pointToLight=light.position-v_Position;float distance=length(pointToLight);float rangeAttenuation=getRangeAttenuation(light.range,distance);float spotAttenuation=getSpotAttenuation(pointToLight,light.direction,light.outerConeCos,light.innerConeCos);vec3 shade=getPointShade(pointToLight,materialInfo,normal,view)*shadow;return rangeAttenuation*spotAttenuation*light.intensity*light.color*shade;}vec3 applyAmbientLight(Light light,MaterialInfo materialInfo){return light.intensity*light.color*diffuse(materialInfo);}float weight(float z,float a){return clamp(pow(min(1.0,a*10.0)+0.01,3.0)*1e8*pow(1.0-z*0.9,3.0),1e-2,3e3);}void main(){float perceptualRoughness=0.0;float metallic=0.0;vec4 baseColor=vec4(0.0,0.0,0.0,1.0);vec3 diffuseColor=vec3(0.0);vec3 specularColor=vec3(0.0);vec3 f0=vec3(0.04);\n#ifdef PREVIEW_BORDER\ngl_FragColor=uPreviewColor;return;\n#endif\n#ifdef MATERIAL_SPECULARGLOSSINESS\n#ifdef HAS_SPECULAR_GLOSSINESS_MAP\nvec4 sgSample=SRGBtoLINEAR(texture2D(_SpecularGlossinessSampler,getSpecularGlossinessUV()));perceptualRoughness=(1.0-sgSample.a*_GlossinessFactor);f0=sgSample.rgb*_SpecularFactor;\n#else\nf0=_SpecularFactor;perceptualRoughness=1.0-_GlossinessFactor;\n#endif\n#ifdef HAS_DIFFUSE_MAP\nbaseColor=SRGBtoLINEAR(texture2D(_DiffuseSampler,getDiffuseUV()))*_DiffuseFactor;\n#else\nbaseColor=SRGBtoLINEAR(_DiffuseFactor);\n#endif\nbaseColor*=getVertexColor();specularColor=f0;float oneMinusSpecularStrength=1.0-max(max(f0.r,f0.g),f0.b);diffuseColor=baseColor.rgb*oneMinusSpecularStrength;\n#ifdef DEBUG_METALLIC\nmetallic=solveMetallic(baseColor.rgb,specularColor,oneMinusSpecularStrength);\n#endif\n#endif\n#ifdef MATERIAL_METALLICROUGHNESS\n#ifdef HAS_METALLIC_ROUGHNESS_MAP\nvec4 mrSample=texture2D(_MetallicRoughnessSampler,getMetallicRoughnessUV());perceptualRoughness=mrSample.g*_RoughnessFactor;metallic=mrSample.b*_MetallicFactor;\n#else\nmetallic=_MetallicFactor;perceptualRoughness=_RoughnessFactor;\n#endif\n#ifdef HAS_BASE_COLOR_MAP\nbaseColor=SRGBtoLINEAR(texture2D(_BaseColorSampler,getBaseColorUV()))*_BaseColorFactor;\n#else\nbaseColor=SRGBtoLINEAR(_BaseColorFactor);\n#endif\nbaseColor*=getVertexColor();diffuseColor=baseColor.rgb*(vec3(1.0)-f0)*(1.0-metallic);specularColor=mix(f0,baseColor.rgb,metallic);\n#endif\n#ifdef ALPHAMODE_MASK\nif(baseColor.a<_AlphaCutoff){discard;}baseColor.a=1.0;\n#endif\n#ifdef ALPHAMODE_OPAQUE\nbaseColor.a=1.0;\n#endif\n#ifdef MATERIAL_UNLIT\n#ifndef DEBUG_OUTPUT\n#ifdef ADD_FOG\nvec3 mixColor=getMixFogColor(baseColor.rgb);vec4 fragColorUnlit=vec4(LINEARtoSRGB(mixColor)*baseColor.a,baseColor.a);\n#else\nvec4 fragColorUnlit=vec4(LINEARtoSRGB(baseColor.rgb)*baseColor.a,baseColor.a);\n#endif\ngl_FragColor=fragColorUnlit;\n#else\n#ifdef DEBUG_UV\ngl_FragColor.rgb=vec3(getDebugUVColor(getBaseColorUV(),getNormal()));\n#endif\n#ifdef DEBUG_METALLIC\ngl_FragColor.rgb=vec3(metallic);\n#endif\n#ifdef DEBUG_ROUGHNESS\ngl_FragColor.rgb=vec3(perceptualRoughness);\n#endif\n#ifdef DEBUG_NORMAL\ngl_FragColor.rgb=getNormal()*0.5+0.5;\n#endif\n#ifdef DEBUG_BASECOLOR\ngl_FragColor.rgb=LINEARtoSRGB(baseColor.rgb);\n#endif\n#ifdef DEBUG_OCCLUSION\ngl_FragColor.rgb=vec3(1.0);\n#endif\n#ifdef DEBUG_EMISSIVE\ngl_FragColor.rgb=vec3(0.0);\n#endif\n#ifdef DEBUG_ALPHA\ngl_FragColor.rgb=vec3(baseColor.a);\n#endif\ngl_FragColor.a=1.0;\n#endif\nreturn;\n#endif\nmetallic=clamp(metallic,0.0,1.0);float alphaRoughness=perceptualRoughness*perceptualRoughness;vec3 normal=getNormal();\n#ifdef USE_SPECULAR_AA\nfloat AARoughnessFactor=getAARoughnessFactor(normal);perceptualRoughness+=AARoughnessFactor;alphaRoughness+=AARoughnessFactor;\n#endif\nperceptualRoughness=clamp(perceptualRoughness,0.04,1.0);alphaRoughness=clamp(alphaRoughness,0.04,1.0);float reflectance=max(max(specularColor.r,specularColor.g),specularColor.b);vec3 specularEnvironmentR0=specularColor.rgb;vec3 specularEnvironmentR90=vec3(clamp(reflectance*50.0,0.0,1.0));MaterialInfo materialInfo=MaterialInfo(perceptualRoughness,specularEnvironmentR0,alphaRoughness,diffuseColor,specularEnvironmentR90,specularColor);vec3 color=vec3(0.0,0.0,0.0);vec3 view=normalize(_Camera-v_Position);float shadow=1.0;\n#ifdef USE_SHADOW_MAPPING\nshadow=getShadowContribution();\n#endif\n#ifdef USE_PUNCTUAL\nfor(int i=0;i<LIGHT_COUNT;++i){Light light=_Lights[i];if(light.type==LightType_Directional){color+=applyDirectionalLight(light,materialInfo,normal,view,shadow);}else if(light.type==LightType_Point){color+=applyPointLight(light,materialInfo,normal,view);}else if(light.type==LightType_Spot){color+=applySpotLight(light,materialInfo,normal,view,shadow);}else if(light.type==LightType_Ambient){color+=applyAmbientLight(light,materialInfo);}}\n#endif\n#ifdef USE_IBL\ncolor+=getIBLContribution(materialInfo,normal,view);\n#endif\nfloat ao=1.0;\n#ifdef HAS_OCCLUSION_MAP\nao=texture2D(_OcclusionSampler,getOcclusionUV()).r;color=mix(color,color*ao,_OcclusionStrength);\n#endif\nvec3 emissive=vec3(0);\n#ifndef DEBUG_OUTPUT\n#ifdef ADD_FOG\nvec4 toneMapColor=SRGBtoLINEAR(vec4(toneMap(color),baseColor.a));color=getMixFogColor(toneMapColor.rgb);vec4 fragColorOut=vec4(LINEARtoSRGB(color.rgb)*baseColor.a,baseColor.a);\n#else\ncolor=toneMap(color)*baseColor.a;\n#ifdef HAS_EMISSIVE\ncolor+=_EmissiveFactor.rgb*_EmissiveIntensity;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(_EmissiveSampler,getEmissiveUV())).rgb*_EmissiveFactor.rgb*_EmissiveIntensity;color+=emissive;\n#endif\nvec4 fragColorOut=vec4(color,baseColor.a);\n#endif\ngl_FragColor=fragColorOut;\n#else\n#ifdef DEBUG_UV\ngl_FragColor.rgb=vec3(getDebugUVColor(getBaseColorUV(),normal));\n#endif\n#ifdef DEBUG_METALLIC\ngl_FragColor.rgb=vec3(metallic);\n#endif\n#ifdef DEBUG_ROUGHNESS\ngl_FragColor.rgb=vec3(perceptualRoughness);\n#endif\n#ifdef DEBUG_NORMAL\ngl_FragColor.rgb=normal*0.5+0.5;\n#endif\n#ifdef DEBUG_BASECOLOR\ngl_FragColor.rgb=LINEARtoSRGB(baseColor.rgb);\n#endif\n#ifdef DEBUG_OCCLUSION\n#ifdef HAS_OCCLUSION_MAP\ngl_FragColor.rgb=vec3(mix(1.0,ao,_OcclusionStrength));\n#else\ngl_FragColor.rgb=vec3(1.0);\n#endif\n#endif\n#ifdef DEBUG_EMISSIVE\n#ifdef HAS_EMISSIVE\nemissive=_EmissiveFactor.rgb*_EmissiveIntensity;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(_EmissiveSampler,getEmissiveUV())).rgb*_EmissiveFactor.rgb*_EmissiveIntensity;\n#endif\ngl_FragColor.rgb=LINEARtoSRGB(emissive);\n#endif\n#ifdef DEBUG_F0\ngl_FragColor.rgb=vec3(f0);\n#endif\n#ifdef DEBUG_ALPHA\ngl_FragColor.rgb=vec3(baseColor.a);\n#endif\ngl_FragColor.a=1.0;\n#endif\n}";
3655
+ var metallicRoughnessFrag = "\n#define FEATURES\n#extension GL_OES_standard_derivatives : enable\n#if defined(USE_TEX_LOD)\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#ifdef USE_HDR\n#extension GL_OES_texture_float : enable\n#extension GL_OES_texture_float_linear : enable\n#endif\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n#include <extensions.frag.glsl>\n#include <tone-mapping.frag.glsl>\n#include <textures.vert.glsl>\n#include <functions.frag.glsl>\n#include <shadow-common.vert.glsl>\n#include <shadow.frag.glsl>\nstruct Light{vec3 direction;float range;vec3 color;float intensity;vec3 position;float innerConeCos;float outerConeCos;int type;vec2 padding;};const int LightType_Directional=0;const int LightType_Point=1;const int LightType_Spot=2;const int LightType_Ambient=3;\n#ifdef USE_PUNCTUAL\nuniform Light _Lights[LIGHT_COUNT];\n#endif\n#if defined(MATERIAL_SPECULARGLOSSINESS) || defined(MATERIAL_METALLICROUGHNESS)\nuniform float _MetallicFactor;uniform float _RoughnessFactor;uniform vec4 _BaseColorFactor;\n#endif\n#ifdef MATERIAL_SPECULARGLOSSINESS\nuniform vec3 _SpecularFactor;uniform vec4 _DiffuseFactor;uniform float _GlossinessFactor;\n#endif\n#ifdef ALPHAMODE_MASK\nuniform float _AlphaCutoff;\n#endif\n#ifdef ADD_FOG\nuniform vec4 _FogColor;\n#ifdef LINEAR_FOG\nuniform float _FogNear;uniform float _FogFar;\n#endif\n#ifdef EXP_FOG\nuniform float _FogDensity;\n#endif\n#endif\n#ifdef PREVIEW_BORDER\nuniform vec4 uPreviewColor;\n#endif\nuniform vec3 _Camera;uniform int _MipCount;struct MaterialInfo{float perceptualRoughness;vec3 reflectance0;float alphaRoughness;vec3 diffuseColor;vec3 reflectance90;vec3 specularColor;};\n#ifdef ADD_FOG\nvec3 getMixFogColor(vec3 baseColor){vec3 distance=_Camera-v_Position;float fogAmount=0.0;\n#ifdef LINEAR_FOG\nfogAmount=smoothstep(_FogNear,_FogFar,distance[2]);\n#endif\n#ifdef EXP_FOG\n#define LOG2 1.442695\nfogAmount=1.-exp2(-_FogDensity*_FogDensity*distance[2]*distance[2]*LOG2);fogAmount=clamp(fogAmount,0.,1.);\n#endif\nvec3 mixColor=baseColor.rgb+(vec3(_FogColor)-baseColor.rgb)*fogAmount;return mixColor;}\n#endif\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 getIrradiance(vec3 norm,SHCoefficients c){float x=norm.x;float y=norm.y;float z=norm.z;float c1=0.429043;float c2=0.511664;float c3=0.743125;float c4=0.886227;float c5=0.247708;vec3 irradiance=c1*c.l22*(x*x-y*y)+c3*c.l20*(z*z)+c4*c.l00-c5*c.l20+2.0*c1*(c.l2m2*x*y+c.l21*x*z+c.l2m1*y*z)+2.0*c2*(c.l11*x+c.l1m1*y+c.l10*z);return irradiance;}\n#endif\n#ifdef USE_IBL\nvec3 getIBLContribution(MaterialInfo materialInfo,vec3 n,vec3 v){float NdotV=clamp(dot(n,v),0.0,1.0);float lod=clamp(materialInfo.perceptualRoughness*float(_MipCount),0.0,float(_MipCount));vec3 reflection=normalize(reflect(-v,n));vec2 brdfSamplePoint=clamp(vec2(NdotV,materialInfo.perceptualRoughness),vec2(0.0,0.0),vec2(1.0,1.0));vec2 brdf=texture2D(_brdfLUT,brdfSamplePoint).rg;vec4 diffuseColor=vec4(1.0,0.0,0.0,1.0);\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 irradiance=getIrradiance(n,_shCoefficients);diffuseColor=vec4(irradiance,1.0);\n#else\ndiffuseColor=textureCube(_DiffuseEnvSampler,n);\n#endif\n#ifdef USE_TEX_LOD\nvec4 specularSample=_textureCubeLodEXT(_SpecularEnvSampler,reflection,lod);\n#else\nvec4 specularSample=textureCube(_SpecularEnvSampler,reflection,lod);\n#endif\n#ifdef USE_HDR\nvec3 diffuseLight=diffuseColor.rgb;vec3 specularLight=specularSample.rgb;\n#else\nvec3 diffuseLight=SRGBtoLINEAR(diffuseColor).rgb;vec3 specularLight=SRGBtoLINEAR(specularSample).rgb;\n#endif\nvec3 diffuse=diffuseLight*materialInfo.diffuseColor;vec3 specular=specularLight*(materialInfo.specularColor*brdf.x+brdf.y);return diffuse*_IblIntensity[0]+specular*_IblIntensity[1];}\n#endif\nvec3 diffuse(MaterialInfo materialInfo){return materialInfo.diffuseColor/M_PI;}vec3 specularReflection(MaterialInfo materialInfo,AngularInfo angularInfo){return materialInfo.reflectance0+(materialInfo.reflectance90-materialInfo.reflectance0)*pow(clamp(1.0-angularInfo.VdotH,0.0,1.0),5.0);}float visibilityOcclusion(MaterialInfo materialInfo,AngularInfo angularInfo){float NdotL=angularInfo.NdotL;float NdotV=angularInfo.NdotV;float alphaRoughnessSq=materialInfo.alphaRoughness*materialInfo.alphaRoughness;float GGXV=NdotL*sqrt(NdotV*NdotV*(1.0-alphaRoughnessSq)+alphaRoughnessSq);float GGXL=NdotV*sqrt(NdotL*NdotL*(1.0-alphaRoughnessSq)+alphaRoughnessSq);float GGX=GGXV+GGXL;if(GGX>0.0){return 0.5/GGX;}return 0.0;}float microfacetDistribution(MaterialInfo materialInfo,AngularInfo angularInfo){float alphaRoughnessSq=materialInfo.alphaRoughness*materialInfo.alphaRoughness;float f=(angularInfo.NdotH*alphaRoughnessSq-angularInfo.NdotH)*angularInfo.NdotH+1.0;return alphaRoughnessSq/(M_PI*f*f);}vec3 getPointShade(vec3 pointToLight,MaterialInfo materialInfo,vec3 normal,vec3 view){AngularInfo angularInfo=getAngularInfo(pointToLight,normal,view);if(angularInfo.NdotL>0.0||angularInfo.NdotV>0.0){vec3 F=specularReflection(materialInfo,angularInfo);float Vis=visibilityOcclusion(materialInfo,angularInfo);float D=microfacetDistribution(materialInfo,angularInfo);vec3 diffuseContrib=(1.0-F)*diffuse(materialInfo);vec3 specContrib=F*Vis*D;return angularInfo.NdotL*(diffuseContrib+specContrib);}return vec3(0.0,0.0,0.0);}float getRangeAttenuation(float range,float distance){if(range<=0.0){return 1.0;}return 1.0/(pow(5.0*distance/range,2.0)+1.0);}float getSpotAttenuation(vec3 pointToLight,vec3 spotDirection,float outerConeCos,float innerConeCos){float actualCos=dot(normalize(spotDirection),normalize(-pointToLight));if(actualCos>outerConeCos){if(actualCos<innerConeCos){return smoothstep(outerConeCos,innerConeCos,actualCos);}return 1.0;}return 0.0;}vec3 applyDirectionalLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view,float shadow){vec3 pointToLight=-light.direction;vec3 shade=getPointShade(pointToLight,materialInfo,normal,view)*shadow;return light.intensity*light.color*shade;}vec3 applyPointLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view){vec3 pointToLight=light.position-v_Position;float distance=length(pointToLight);float attenuation=getRangeAttenuation(light.range,distance);vec3 shade=getPointShade(pointToLight,materialInfo,normal,view);return light.color*shade*attenuation*light.intensity;}vec3 applySpotLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view,float shadow){vec3 pointToLight=light.position-v_Position;float distance=length(pointToLight);float rangeAttenuation=getRangeAttenuation(light.range,distance);float spotAttenuation=getSpotAttenuation(pointToLight,light.direction,light.outerConeCos,light.innerConeCos);vec3 shade=getPointShade(pointToLight,materialInfo,normal,view)*shadow;return rangeAttenuation*spotAttenuation*light.intensity*light.color*shade;}vec3 applyAmbientLight(Light light,MaterialInfo materialInfo){return light.intensity*light.color*diffuse(materialInfo);}float weight(float z,float a){return clamp(pow(min(1.0,a*10.0)+0.01,3.0)*1e8*pow(1.0-z*0.9,3.0),1e-2,3e3);}void main(){float perceptualRoughness=0.0;float metallic=0.0;vec4 baseColor=vec4(0.0,0.0,0.0,1.0);vec3 diffuseColor=vec3(0.0);vec3 specularColor=vec3(0.0);vec3 f0=vec3(0.04);\n#ifdef PREVIEW_BORDER\ngl_FragColor=uPreviewColor;return;\n#endif\n#ifdef MATERIAL_SPECULARGLOSSINESS\n#ifdef HAS_SPECULAR_GLOSSINESS_MAP\nvec4 sgSample=SRGBtoLINEAR(texture2D(_SpecularGlossinessSampler,getSpecularGlossinessUV()));perceptualRoughness=(1.0-sgSample.a*_GlossinessFactor);f0=sgSample.rgb*_SpecularFactor;\n#else\nf0=_SpecularFactor;perceptualRoughness=1.0-_GlossinessFactor;\n#endif\n#ifdef HAS_DIFFUSE_MAP\nbaseColor=SRGBtoLINEAR(texture2D(_DiffuseSampler,getDiffuseUV()))*_DiffuseFactor;\n#else\nbaseColor=SRGBtoLINEAR(_DiffuseFactor);\n#endif\nbaseColor*=getVertexColor();specularColor=f0;float oneMinusSpecularStrength=1.0-max(max(f0.r,f0.g),f0.b);diffuseColor=baseColor.rgb*oneMinusSpecularStrength;\n#ifdef DEBUG_METALLIC\nmetallic=solveMetallic(baseColor.rgb,specularColor,oneMinusSpecularStrength);\n#endif\n#endif\n#ifdef MATERIAL_METALLICROUGHNESS\n#ifdef HAS_METALLIC_ROUGHNESS_MAP\nvec4 mrSample=texture2D(_MetallicRoughnessSampler,getMetallicRoughnessUV());perceptualRoughness=mrSample.g*_RoughnessFactor;metallic=mrSample.b*_MetallicFactor;\n#else\nmetallic=_MetallicFactor;perceptualRoughness=_RoughnessFactor;\n#endif\n#ifdef HAS_BASE_COLOR_MAP\nbaseColor=SRGBtoLINEAR(texture2D(_BaseColorSampler,getBaseColorUV()))*_BaseColorFactor;\n#else\nbaseColor=SRGBtoLINEAR(_BaseColorFactor);\n#endif\nbaseColor*=getVertexColor();diffuseColor=baseColor.rgb*(vec3(1.0)-f0)*(1.0-metallic);specularColor=mix(f0,baseColor.rgb,metallic);\n#endif\n#ifdef ALPHAMODE_MASK\nif(baseColor.a<_AlphaCutoff){discard;}baseColor.a=1.0;\n#endif\n#ifdef ALPHAMODE_OPAQUE\nbaseColor.a=1.0;\n#endif\n#ifdef MATERIAL_UNLIT\n#ifndef DEBUG_OUTPUT\n#ifdef ADD_FOG\nvec3 mixColor=getMixFogColor(baseColor.rgb);vec4 fragColorUnlit=vec4(LINEARtoSRGB(mixColor)*baseColor.a,baseColor.a);\n#else\nvec4 fragColorUnlit=vec4(LINEARtoSRGB(baseColor.rgb)*baseColor.a,baseColor.a);\n#endif\ngl_FragColor=fragColorUnlit;\n#else\n#ifdef DEBUG_UV\ngl_FragColor.rgb=vec3(getDebugUVColor(getBaseColorUV(),getNormal()));\n#endif\n#ifdef DEBUG_METALLIC\ngl_FragColor.rgb=vec3(metallic);\n#endif\n#ifdef DEBUG_ROUGHNESS\ngl_FragColor.rgb=vec3(perceptualRoughness);\n#endif\n#ifdef DEBUG_NORMAL\ngl_FragColor.rgb=getNormal()*0.5+0.5;\n#endif\n#ifdef DEBUG_BASECOLOR\ngl_FragColor.rgb=LINEARtoSRGB(baseColor.rgb);\n#endif\n#ifdef DEBUG_OCCLUSION\ngl_FragColor.rgb=vec3(1.0);\n#endif\n#ifdef DEBUG_EMISSIVE\ngl_FragColor.rgb=vec3(0.0);\n#endif\n#ifdef DEBUG_ALPHA\ngl_FragColor.rgb=vec3(baseColor.a);\n#endif\ngl_FragColor.a=1.0;\n#endif\nreturn;\n#endif\nmetallic=clamp(metallic,0.0,1.0);float alphaRoughness=perceptualRoughness*perceptualRoughness;vec3 normal=getNormal();\n#ifdef USE_SPECULAR_AA\nfloat AARoughnessFactor=getAARoughnessFactor(normal);perceptualRoughness+=AARoughnessFactor;alphaRoughness+=AARoughnessFactor;\n#endif\nperceptualRoughness=clamp(perceptualRoughness,0.04,1.0);alphaRoughness=clamp(alphaRoughness,0.04,1.0);float reflectance=max(max(specularColor.r,specularColor.g),specularColor.b);vec3 specularEnvironmentR0=specularColor.rgb;vec3 specularEnvironmentR90=vec3(clamp(reflectance*50.0,0.0,1.0));MaterialInfo materialInfo=MaterialInfo(perceptualRoughness,specularEnvironmentR0,alphaRoughness,diffuseColor,specularEnvironmentR90,specularColor);vec3 color=vec3(0.0,0.0,0.0);vec3 view=normalize(_Camera-v_Position);float shadow=1.0;\n#ifdef USE_SHADOW_MAPPING\nshadow=getShadowContribution();\n#endif\n#ifdef USE_PUNCTUAL\nfor(int i=0;i<LIGHT_COUNT;++i){Light light=_Lights[i];if(light.type==LightType_Directional){color+=applyDirectionalLight(light,materialInfo,normal,view,shadow);}else if(light.type==LightType_Point){color+=applyPointLight(light,materialInfo,normal,view);}else if(light.type==LightType_Spot){color+=applySpotLight(light,materialInfo,normal,view,shadow);}else if(light.type==LightType_Ambient){color+=applyAmbientLight(light,materialInfo);}}\n#endif\n#ifdef USE_IBL\ncolor+=getIBLContribution(materialInfo,normal,view);\n#endif\nfloat ao=1.0;\n#ifdef HAS_OCCLUSION_MAP\nao=texture2D(_OcclusionSampler,getOcclusionUV()).r;color=mix(color,color*ao,_OcclusionStrength);\n#endif\nvec3 emissive=vec3(0);\n#ifndef DEBUG_OUTPUT\n#ifdef ADD_FOG\nvec4 toneMapColor=SRGBtoLINEAR(vec4(toneMap(color),baseColor.a));color=getMixFogColor(toneMapColor.rgb);vec4 fragColorOut=vec4(LINEARtoSRGB(color.rgb)*baseColor.a,baseColor.a);\n#else\ncolor=toneMap(color)*baseColor.a;\n#ifdef HAS_EMISSIVE\ncolor+=_EmissiveFactor.rgb*_EmissiveIntensity;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(_EmissiveSampler,getEmissiveUV())).rgb*_EmissiveFactor.rgb*_EmissiveIntensity;color+=emissive;\n#endif\nvec4 fragColorOut=vec4(color,baseColor.a);\n#endif\ngl_FragColor=fragColorOut;\n#else\n#ifdef DEBUG_UV\ngl_FragColor.rgb=vec3(getDebugUVColor(getBaseColorUV(),normal));\n#endif\n#ifdef DEBUG_METALLIC\ngl_FragColor.rgb=vec3(metallic);\n#endif\n#ifdef DEBUG_ROUGHNESS\ngl_FragColor.rgb=vec3(perceptualRoughness);\n#endif\n#ifdef DEBUG_NORMAL\ngl_FragColor.rgb=normal*0.5+0.5;\n#endif\n#ifdef DEBUG_BASECOLOR\ngl_FragColor.rgb=LINEARtoSRGB(baseColor.rgb);\n#endif\n#ifdef DEBUG_OCCLUSION\n#ifdef HAS_OCCLUSION_MAP\ngl_FragColor.rgb=vec3(mix(1.0,ao,_OcclusionStrength));\n#else\ngl_FragColor.rgb=vec3(1.0);\n#endif\n#endif\n#ifdef DEBUG_EMISSIVE\n#ifdef HAS_EMISSIVE\nemissive=_EmissiveFactor.rgb*_EmissiveIntensity;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(_EmissiveSampler,getEmissiveUV())).rgb*_EmissiveFactor.rgb*_EmissiveIntensity;\n#endif\ngl_FragColor.rgb=LINEARtoSRGB(emissive);\n#endif\n#ifdef DEBUG_F0\ngl_FragColor.rgb=vec3(f0);\n#endif\n#ifdef DEBUG_ALPHA\ngl_FragColor.rgb=vec3(baseColor.a);\n#endif\n#ifdef DEBUG_DIFFUSE\nvec3 debugDiffuse=vec3(0.0);\n#ifdef USE_PUNCTUAL\nMaterialInfo diffuseMaterialInfo=MaterialInfo(1.0,f0,1.0,vec3(0.35),f0,f0);for(int i=0;i<LIGHT_COUNT;++i){Light light=_Lights[i];if(light.type==LightType_Directional){debugDiffuse+=applyDirectionalLight(light,diffuseMaterialInfo,normal,view,shadow);}else if(light.type==LightType_Point){debugDiffuse+=applyPointLight(light,diffuseMaterialInfo,normal,view);}else if(light.type==LightType_Spot){debugDiffuse+=applySpotLight(light,diffuseMaterialInfo,normal,view,shadow);}else if(light.type==LightType_Ambient){debugDiffuse+=applyAmbientLight(light,diffuseMaterialInfo);}}\n#ifdef USE_IBL\ndebugDiffuse+=getIBLContribution(diffuseMaterialInfo,normal,view);\n#endif\n#endif\ngl_FragColor.rgb=toneMap(debugDiffuse);\n#endif\ngl_FragColor.a=1.0;\n#endif\n}";
3930
3656
 
3931
3657
  var shadowPassFrag = "#define FEATURES\n#include <shadow-common.vert.glsl>\n#if defined(SHADOWMAP_VSM)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\nvec4 CalcMomentVSM(float depth){float dx=0.0;float dy=0.0;\n#if defined(SHADOWMAP_VSM) && (defined(GL_OES_standard_derivatives) || defined(WEBGL2))\ndx=dFdx(depth);dy=dFdy(depth);\n#endif\nfloat moment2=depth*depth+0.25*(dx*dx+dy*dy);return vec4(1.0-depth,1.0-moment2,0.0,1.0);}vec4 CalcMomentEVSM(float depth){float pos=EVSM_FUNC0(depth);float neg=EVSM_FUNC1(depth);return vec4(pos,pos*pos,neg,neg*neg);}void main(){\n#if defined(SHADOWMAP_STANDARD) || defined(SHADOWMAP_VSM)\ngl_FragColor=CalcMomentVSM(gl_FragCoord.z);\n#else\ngl_FragColor=CalcMomentEVSM(gl_FragCoord.z);\n#endif\n}";
3932
3658
 
@@ -6159,31 +5885,6 @@ var normal = new Vector3();
6159
5885
  console.error("setupItem3DOptions: Invalid inverseBindMatrices type, " + inverseBindMatrices + ".");
6160
5886
  }
6161
5887
  }
6162
- } else if (item.type === spec.ItemType.tree) {
6163
- var jsonItem = item;
6164
- var studioItem = item;
6165
- var jsonAnimations = jsonItem.content.options.tree.animations;
6166
- var studioAnimations = studioItem.content.options.tree.animations;
6167
- if (jsonAnimations !== undefined && studioAnimations !== undefined) {
6168
- jsonAnimations.forEach(function(jsonAnim, i) {
6169
- var studioAnim = studioAnimations[i];
6170
- jsonAnim.tracks.forEach(function(jsonTrack, j) {
6171
- var inputArray = typedArrayFromBinary(scene.bins, jsonTrack.input);
6172
- var outputArray = typedArrayFromBinary(scene.bins, jsonTrack.output);
6173
- var studioTrack = studioAnim.tracks[j];
6174
- if (_instanceof1(inputArray, Float32Array)) {
6175
- studioTrack.input = inputArray;
6176
- } else {
6177
- console.error("setupItem3DOptions: Type of inputArray should be float32, " + inputArray + ".");
6178
- }
6179
- if (_instanceof1(outputArray, Float32Array)) {
6180
- studioTrack.output = outputArray;
6181
- } else {
6182
- console.error("setupItem3DOptions: Type of outputArray should be float32, " + outputArray + ".");
6183
- }
6184
- });
6185
- });
6186
- }
6187
5888
  } else if (item.type === spec.ItemType.skybox) {
6188
5889
  var skybox = item;
6189
5890
  var studioSkybox = item;
@@ -9906,117 +9607,6 @@ ModelPluginComponent = __decorate([
9906
9607
  return pluginComp == null ? void 0 : pluginComp.scene;
9907
9608
  }
9908
9609
 
9909
- /**
9910
- * 场景树元素类,支持插件中节点树相关的动画能力
9911
- */ var ModelTreeItem = /*#__PURE__*/ function() {
9912
- function ModelTreeItem(props, owner) {
9913
- this.baseTransform = owner.transform;
9914
- this.animationManager = new PAnimationManager(props, owner);
9915
- this.build(props);
9916
- }
9917
- var _proto = ModelTreeItem.prototype;
9918
- /**
9919
- * 场景树更新,主要是动画更新
9920
- * @param dt - 时间间隔
9921
- */ _proto.tick = function tick(dt) {
9922
- this.animationManager.tick(dt);
9923
- };
9924
- /**
9925
- * 获取所有节点
9926
- * @returns
9927
- */ _proto.getNodes = function getNodes() {
9928
- return this.nodes;
9929
- };
9930
- /**
9931
- * 根据节点编号,查询节点
9932
- * @param nodeId - 节点编号
9933
- * @returns
9934
- */ _proto.getNodeById = function getNodeById(nodeId) {
9935
- var cache = this.cacheMap;
9936
- if (!cache[nodeId]) {
9937
- var index = "^" + nodeId;
9938
- // @ts-expect-error
9939
- cache[nodeId] = this.allNodes.find(function(node) {
9940
- return node.id === index;
9941
- });
9942
- }
9943
- return cache[nodeId];
9944
- };
9945
- /**
9946
- * 根据节点名称,查询节点
9947
- * @param name - 名称
9948
- * @returns
9949
- */ _proto.getNodeByName = function getNodeByName(name) {
9950
- var cache = this.cacheMap;
9951
- if (!cache[name]) {
9952
- // @ts-expect-error
9953
- cache[name] = this.allNodes.find(function(node) {
9954
- return node.name === name;
9955
- });
9956
- }
9957
- return cache[name];
9958
- };
9959
- /**
9960
- * 根据节点 id 查询节点变换,如果查询不到节点就直接返回基础变换
9961
- * @param nodeId - 节点 id
9962
- * @returns
9963
- */ _proto.getNodeTransform = function getNodeTransform(nodeId) {
9964
- var node = this.getNodeById(nodeId);
9965
- return node ? node.transform : this.baseTransform;
9966
- };
9967
- /**
9968
- * 销毁场景树对象
9969
- */ _proto.dispose = function dispose() {
9970
- var _this_animationManager;
9971
- this.allNodes = [];
9972
- this.nodes = [];
9973
- this.cacheMap = {};
9974
- // @ts-expect-error
9975
- this.baseTransform = null;
9976
- (_this_animationManager = this.animationManager) == null ? void 0 : _this_animationManager.dispose();
9977
- // @ts-expect-error
9978
- this.animationManager = null;
9979
- };
9980
- _proto.build = function build(options) {
9981
- var _this = this;
9982
- var topTransform = this.baseTransform;
9983
- var nodes = options.nodes.map(function(node, i) {
9984
- return {
9985
- name: node.name || node.id || i + "",
9986
- transform: new Transform(_extends({}, node.transform, {
9987
- valid: true
9988
- }), topTransform),
9989
- id: "^" + (node.id || i),
9990
- children: [],
9991
- tree: _this
9992
- };
9993
- });
9994
- this.cacheMap = {};
9995
- nodes.forEach(function(node, i) {
9996
- var children = options.nodes[i].children;
9997
- // @ts-expect-error
9998
- node.transform.name = node.name;
9999
- node.transform.setValid(true);
10000
- if (children) {
10001
- children.forEach(function(index) {
10002
- var child = nodes[index];
10003
- if (child && child !== node) {
10004
- if (child.transform.parentTransform !== topTransform) {
10005
- console.error("Node parent has been set.");
10006
- }
10007
- child.transform.parentTransform = node.transform;
10008
- node.children.push(child);
10009
- }
10010
- });
10011
- }
10012
- });
10013
- this.allNodes = nodes;
10014
- this.nodes = options.children.map(function(i) {
10015
- return nodes[i];
10016
- });
10017
- };
10018
- return ModelTreeItem;
10019
- }();
10020
9610
  var ModelTreeComponent = /*#__PURE__*/ function(Behaviour) {
10021
9611
  _inherits(ModelTreeComponent, Behaviour);
10022
9612
  function ModelTreeComponent(engine, options) {
@@ -10034,56 +9624,6 @@ var ModelTreeComponent = /*#__PURE__*/ function(Behaviour) {
10034
9624
  */ _proto.fromData = function fromData(options) {
10035
9625
  Behaviour.prototype.fromData.call(this, options);
10036
9626
  this.options = options;
10037
- this.createContent();
10038
- };
10039
- /**
10040
- * 组件开始,查询合成中场景管理器并设置到动画管理器中
10041
- */ _proto.onStart = function onStart() {
10042
- this.item.type = spec.ItemType.tree;
10043
- this.content.baseTransform.setValid(true);
10044
- var sceneManager = getSceneManager(this);
10045
- if (sceneManager) {
10046
- this.content.animationManager.setSceneManager(sceneManager);
10047
- }
10048
- };
10049
- /**
10050
- * 组件更新,内部对象更新
10051
- * @param dt
10052
- */ _proto.onUpdate = function onUpdate(dt) {
10053
- var // this.timeline?.getRenderData(time, true);
10054
- // TODO: 需要使用lifetime
10055
- _this_content;
10056
- (_this_content = this.content) == null ? void 0 : _this_content.tick(dt);
10057
- };
10058
- /**
10059
- * 组件销毁,内部对象销毁
10060
- */ _proto.onDestroy = function onDestroy() {
10061
- var _this_content;
10062
- (_this_content = this.content) == null ? void 0 : _this_content.dispose();
10063
- };
10064
- /**
10065
- * 创建内部场景树元素
10066
- */ _proto.createContent = function createContent() {
10067
- if (this.options) {
10068
- var treeOptions = this.options.options.tree;
10069
- this.content = new ModelTreeItem(treeOptions, this.item);
10070
- }
10071
- };
10072
- /**
10073
- * 获取元素的变换
10074
- * @param itemId - 元素索引
10075
- * @returns
10076
- */ _proto.getNodeTransform = function getNodeTransform(itemId) {
10077
- if (this.content === undefined) {
10078
- return this.transform;
10079
- }
10080
- var idWithSubfix = this.item.id + "^";
10081
- if (itemId.indexOf(idWithSubfix) === 0) {
10082
- var nodeId = itemId.substring(idWithSubfix.length);
10083
- return this.content.getNodeTransform(nodeId);
10084
- } else {
10085
- return this.transform;
10086
- }
10087
9627
  };
10088
9628
  return ModelTreeComponent;
10089
9629
  }(Behaviour);
@@ -10091,24 +9631,6 @@ ModelTreeComponent = __decorate([
10091
9631
  effectsClass(spec.DataType.TreeComponent)
10092
9632
  ], ModelTreeComponent);
10093
9633
 
10094
- /**
10095
- * 场景树插件类,支持 3D 相关的节点动画和骨骼动画等
10096
- */ var ModelTreePlugin = /*#__PURE__*/ function(AbstractPlugin) {
10097
- _inherits(ModelTreePlugin, AbstractPlugin);
10098
- function ModelTreePlugin() {
10099
- var _this;
10100
- _this = AbstractPlugin.apply(this, arguments) || this;
10101
- /**
10102
- * 插件名称
10103
- */ _this.name = "tree";
10104
- /**
10105
- * 高优先级更新
10106
- */ _this.order = 2;
10107
- return _this;
10108
- }
10109
- return ModelTreePlugin;
10110
- }(AbstractPlugin);
10111
-
10112
9634
  var CameraGestureType;
10113
9635
  (function(CameraGestureType) {
10114
9636
  CameraGestureType[CameraGestureType["none"] = 0] = "none";
@@ -10134,6 +9656,9 @@ var CameraGestureHandlerImp = /*#__PURE__*/ function() {
10134
9656
  };
10135
9657
  }
10136
9658
  var _proto = CameraGestureHandlerImp.prototype;
9659
+ _proto.updateComposition = function updateComposition(composition) {
9660
+ this.composition = composition;
9661
+ };
10137
9662
  _proto.getItem = function getItem() {
10138
9663
  var _this = this;
10139
9664
  var _this_composition_items;
@@ -10643,7 +10168,7 @@ var JSONConverter = /*#__PURE__*/ function() {
10643
10168
  _proto.processScene = function processScene(sceneData) {
10644
10169
  var _this = this;
10645
10170
  return _async_to_generator(function() {
10646
- var sceneJSON, _tmp, oldScene, _oldScene_bins, oldBinUrls, binFiles, _iterator, _step, bin, _, newScene;
10171
+ var sceneJSON, _tmp, oldScene, _oldScene_bins, oldBinUrls, binFiles, v, _iterator, _step, bin, _, newScene;
10647
10172
  return __generator(this, function(_state) {
10648
10173
  switch(_state.label){
10649
10174
  case 0:
@@ -10680,6 +10205,14 @@ var JSONConverter = /*#__PURE__*/ function() {
10680
10205
  oldScene = getStandardJSON(sceneJSON);
10681
10206
  oldBinUrls = (_oldScene_bins = oldScene.bins) != null ? _oldScene_bins : [];
10682
10207
  binFiles = [];
10208
+ //@ts-expect-error
10209
+ v = sceneJSON.version.split(".");
10210
+ if (Number(v[0]) >= 3) {
10211
+ return [
10212
+ 2,
10213
+ oldScene
10214
+ ];
10215
+ }
10683
10216
  if (!oldScene.bins) return [
10684
10217
  3,
10685
10218
  7
@@ -10879,7 +10412,6 @@ var JSONConverter = /*#__PURE__*/ function() {
10879
10412
  this.createItemsFromTreeComponent(comp, newScene, oldScene);
10880
10413
  treeComp.options.tree.animation = undefined;
10881
10414
  treeComp.options.tree.animations = undefined;
10882
- newComponents.push(comp);
10883
10415
  } else if (comp.dataType !== spec.DataType.MeshComponent) {
10884
10416
  newComponents.push(comp);
10885
10417
  }
@@ -11317,6 +10849,7 @@ var JSONConverter = /*#__PURE__*/ function() {
11317
10849
  });
11318
10850
  });
11319
10851
  }
10852
+ treeItem.components = [];
11320
10853
  treeItem.components.push({
11321
10854
  id: animationComponent.id
11322
10855
  });
@@ -12023,11 +11556,7 @@ function setDefaultEffectsGLTFLoader(loader) {
12023
11556
  var defaultGLTFLoader;
12024
11557
  var LoaderImpl = /*#__PURE__*/ function() {
12025
11558
  function LoaderImpl(composition) {
12026
- this.gltfSkins = [];
12027
11559
  this.gltfMeshs = [];
12028
- this.gltfLights = [];
12029
- this.gltfCameras = [];
12030
- this.gltfImages = [];
12031
11560
  this.gltfTextures = [];
12032
11561
  this.gltfMaterials = [];
12033
11562
  this.gltfAnimations = [];
@@ -12050,7 +11579,7 @@ var LoaderImpl = /*#__PURE__*/ function() {
12050
11579
  this.composition = {
12051
11580
  id: "1",
12052
11581
  name: "test1",
12053
- duration: 9999,
11582
+ duration: 99999,
12054
11583
  endBehavior: spec.EndBehavior.restart,
12055
11584
  camera: {
12056
11585
  fov: 45,
@@ -12119,12 +11648,7 @@ var LoaderImpl = /*#__PURE__*/ function() {
12119
11648
  case 1:
12120
11649
  _this.imageElements = _state.sent();
12121
11650
  _this.processGLTFResource(gltfResource, _this.imageElements);
12122
- _this.gltfScene = gltfResource.scenes[0];
12123
- _this.gltfSkins = _this.gltfScene.skins;
12124
11651
  _this.gltfMeshs = gltfResource.meshes;
12125
- _this.gltfLights = _this.gltfScene.lights;
12126
- _this.gltfCameras = _this.gltfScene.cameras;
12127
- _this.gltfImages = gltfResource.images;
12128
11652
  _this.gltfTextures = gltfResource.textures;
12129
11653
  _this.gltfMaterials = gltfResource.materials;
12130
11654
  _this.gltfAnimations = gltfResource.animations;
@@ -12574,7 +12098,8 @@ var LoaderImpl = /*#__PURE__*/ function() {
12574
12098
  intensity: data.intensity,
12575
12099
  range: data.range,
12576
12100
  innerConeAngle: data.innerConeAngle,
12577
- outerConeAngle: data.outerConeAngle
12101
+ outerConeAngle: data.outerConeAngle,
12102
+ followCamera: data.followCamera
12578
12103
  };
12579
12104
  var item = {
12580
12105
  id: itemId,
@@ -12662,6 +12187,59 @@ var LoaderImpl = /*#__PURE__*/ function() {
12662
12187
  this.items.push(item);
12663
12188
  this.components.push(component);
12664
12189
  };
12190
+ _proto.addSkybox = function addSkybox(skybox) {
12191
+ var _this_images, // @ts-expect-error
12192
+ _this_textures;
12193
+ var itemId = generateGUID();
12194
+ var skyboxInfo = PSkyboxCreator.createSkyboxComponentData(skybox);
12195
+ var imageList = skyboxInfo.imageList, textureOptionsList = skyboxInfo.textureOptionsList, component = skyboxInfo.component;
12196
+ component.item.id = itemId;
12197
+ if (skybox.intensity !== undefined) {
12198
+ component.intensity = skybox.intensity;
12199
+ }
12200
+ if (skybox.reflectionsIntensity !== undefined) {
12201
+ component.reflectionsIntensity = skybox.reflectionsIntensity;
12202
+ }
12203
+ var _skybox_renderable;
12204
+ component.renderable = (_skybox_renderable = skybox.renderable) != null ? _skybox_renderable : false;
12205
+ var item = {
12206
+ id: itemId,
12207
+ name: "Skybox-Customize",
12208
+ duration: 999,
12209
+ type: spec.ItemType.skybox,
12210
+ pn: 0,
12211
+ visible: true,
12212
+ endBehavior: spec.EndBehavior.freeze,
12213
+ transform: {
12214
+ position: {
12215
+ x: 0,
12216
+ y: 0,
12217
+ z: 0
12218
+ },
12219
+ eulerHint: {
12220
+ x: 0,
12221
+ y: 0,
12222
+ z: 0
12223
+ },
12224
+ scale: {
12225
+ x: 1,
12226
+ y: 1,
12227
+ z: 1
12228
+ }
12229
+ },
12230
+ components: [
12231
+ {
12232
+ id: component.id
12233
+ }
12234
+ ],
12235
+ content: {},
12236
+ dataType: spec.DataType.VFXItemData
12237
+ };
12238
+ (_this_images = this.images).push.apply(_this_images, [].concat(imageList));
12239
+ (_this_textures = this.textures).push.apply(_this_textures, [].concat(textureOptionsList));
12240
+ this.items.push(item);
12241
+ this.components.push(component);
12242
+ };
12665
12243
  _proto.tryAddSkybox = function tryAddSkybox(skybox) {
12666
12244
  var _this = this;
12667
12245
  return _async_to_generator(function() {
@@ -12736,14 +12314,26 @@ var LoaderImpl = /*#__PURE__*/ function() {
12736
12314
  var params = PSkyboxCreator.getSkyboxParams(typ);
12737
12315
  return PSkyboxCreator.createSkyboxComponentData(params);
12738
12316
  };
12317
+ _proto.dispose = function dispose() {
12318
+ this.clear();
12319
+ // @ts-expect-error
12320
+ this.engine = null;
12321
+ };
12739
12322
  _proto.clear = function clear() {
12323
+ this.gltfMeshs = [];
12324
+ this.gltfTextures = [];
12325
+ this.gltfMaterials = [];
12326
+ this.gltfAnimations = [];
12327
+ this.gltfImageBasedLights = [];
12740
12328
  this.images = [];
12329
+ this.imageElements = [];
12741
12330
  this.textures = [];
12742
12331
  this.items = [];
12743
12332
  this.components = [];
12744
12333
  this.materials = [];
12745
12334
  this.shaders = [];
12746
12335
  this.geometries = [];
12336
+ this.animations = [];
12747
12337
  };
12748
12338
  _proto.computeSceneAABB = function computeSceneAABB() {
12749
12339
  var geometryDataMap = {};
@@ -12784,43 +12374,6 @@ var LoaderImpl = /*#__PURE__*/ function() {
12784
12374
  });
12785
12375
  return sceneAABB;
12786
12376
  };
12787
- /**
12788
- * 按照传入的动画播放参数,计算需要播放的动画索引
12789
- *
12790
- * @param treeOptions 节点树属性,需要初始化animations列表。
12791
- * @returns 返回计算的动画索引,-1表示没有动画需要播放,-88888888表示播放所有动画。
12792
- */ _proto.getPlayAnimationIndex = function getPlayAnimationIndex(treeOptions) {
12793
- var animations = treeOptions.animations;
12794
- if (animations === undefined || animations.length <= 0) {
12795
- // 硬编码,内部指定的不播放动画的索引值
12796
- return -1;
12797
- }
12798
- if (this.isPlayAllAnimation()) {
12799
- // 硬编码,内部指定的播放全部动画的索引值
12800
- return -88888888;
12801
- }
12802
- var animationInfo = this.sceneOptions.effects.playAnimation;
12803
- if (animationInfo === undefined) {
12804
- return -1;
12805
- }
12806
- if (typeof animationInfo === "number") {
12807
- if (animationInfo >= 0 && animationInfo < animations.length) {
12808
- return animationInfo;
12809
- } else {
12810
- return -1;
12811
- }
12812
- } else {
12813
- // typeof animationInfo === 'string'
12814
- var animationIndex = -1;
12815
- // 通过动画名字查找动画索引
12816
- animations.forEach(function(anim, index) {
12817
- if (anim.name === animationInfo) {
12818
- animationIndex = index;
12819
- }
12820
- });
12821
- return animationIndex;
12822
- }
12823
- };
12824
12377
  _proto.isPlayAnimation = function isPlayAnimation() {
12825
12378
  return this.sceneOptions.effects.playAnimation !== undefined;
12826
12379
  };
@@ -12962,64 +12515,6 @@ var LoaderImpl = /*#__PURE__*/ function() {
12962
12515
  }
12963
12516
  });
12964
12517
  };
12965
- _proto.createTreeOptions = function createTreeOptions(scene) {
12966
- var nodeList = scene.nodes.map(function(node, nodeIndex) {
12967
- var children = node.children.map(function(child) {
12968
- if (child.nodeIndex === undefined) {
12969
- throw new Error("Undefined nodeIndex for child " + child);
12970
- }
12971
- return child.nodeIndex;
12972
- });
12973
- var pos;
12974
- var quat;
12975
- var scale;
12976
- if (node.matrix !== undefined) {
12977
- if (node.matrix.length !== 16) {
12978
- throw new Error("Invalid matrix length " + node.matrix.length + " for node " + node);
12979
- }
12980
- var mat = Matrix4.fromArray(node.matrix);
12981
- var transform = mat.getTransform();
12982
- pos = transform.translation.toArray();
12983
- quat = transform.rotation.toArray();
12984
- scale = transform.scale.toArray();
12985
- } else {
12986
- if (node.translation !== undefined) {
12987
- pos = node.translation;
12988
- }
12989
- if (node.rotation !== undefined) {
12990
- quat = node.rotation;
12991
- }
12992
- if (node.scale !== undefined) {
12993
- scale = node.scale;
12994
- }
12995
- }
12996
- node.nodeIndex = nodeIndex;
12997
- var treeNode = {
12998
- name: node.name,
12999
- transform: {
13000
- position: pos,
13001
- quat: quat,
13002
- scale: scale
13003
- },
13004
- children: children,
13005
- id: "" + node.nodeIndex
13006
- };
13007
- return treeNode;
13008
- });
13009
- var rootNodes = scene.rootNodes.map(function(root) {
13010
- if (root.nodeIndex === undefined) {
13011
- throw new Error("Undefined nodeIndex for root " + root);
13012
- }
13013
- return root.nodeIndex;
13014
- });
13015
- var treeOptions = {
13016
- nodes: nodeList,
13017
- children: rootNodes,
13018
- animation: -1,
13019
- animations: []
13020
- };
13021
- return treeOptions;
13022
- };
13023
12518
  _proto.createAnimations = function createAnimations(animations) {
13024
12519
  return animations.map(function(anim) {
13025
12520
  var tracks = anim.channels.map(function(channel) {
@@ -13218,7 +12713,7 @@ function getDefaultUnlitMaterialData() {
13218
12713
  },
13219
12714
  "macros": [],
13220
12715
  "shader": {
13221
- "id": "unlit000000000000000000000000000"
12716
+ "id": spec.BuiltinObjectGUID.UnlitShader
13222
12717
  },
13223
12718
  "ints": {},
13224
12719
  "floats": {
@@ -13769,13 +13264,14 @@ var GLTFHelper = /*#__PURE__*/ function() {
13769
13264
  return GLTFHelper;
13770
13265
  }();
13771
13266
 
13772
- registerPlugin("tree", ModelTreePlugin, VFXItem, true);
13773
13267
  registerPlugin("model", ModelPlugin, VFXItem);
13774
- var version = "2.1.0-alpha.1";
13268
+ /**
13269
+ * 插件版本号
13270
+ */ var version = "2.1.0-alpha.10";
13775
13271
  logger.info("Plugin model version: " + version + ".");
13776
13272
  if (version !== EFFECTS.version) {
13777
13273
  console.error("注意:请统一 Model 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Model plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
13778
13274
  }
13779
13275
 
13780
- export { AnimationComponent, Box3, BoxMesh, CameraGestureHandlerImp, CameraGestureType, CheckerHelper, Color, CompositionCache, CompositionHitTest, DEG2RAD, Euler, EulerOrder, FBOOptions, Float16ArrayWrapper, GeometryBoxProxy, HitTestingProxy, HookOGLFunc, InterpolationSampler, JSONConverter, LoaderHelper, LoaderImpl, Matrix3, Matrix4, MeshHelper, ModelCameraComponent, ModelLightComponent, ModelMeshComponent, ModelPlugin, ModelPluginComponent, ModelSkyboxComponent, ModelTreeComponent, ModelTreeItem, ModelTreePlugin, PAnimInterpType, PAnimPathType, PAnimTexture, PAnimTrack, PAnimation, PAnimationManager, PBRShaderGUID, PBlendMode, PCamera, PCameraManager, PCoordinate, PEntity, PFaceSideMode, PGeometry, PGlobalState, PLight, PLightManager, PLightType, PMaterialBase, PMaterialPBR, PMaterialSkyboxFilter, PMaterialType, PMaterialUnlit, PMesh, PMorph, PObject, PObjectType, PSceneManager, PShaderManager, PShadowType, PSkin, PSkybox, PSkyboxCreator, PSkyboxType, PSubMesh, PTextureType, PTransform, PluginHelper, Quaternion, Ray, RayBoxTesting, RayIntersectsBoxWithRotation, RayTriangleTesting, Sphere, TextureDataMode, ToggleItemBounding, TwoStatesSet, UnlitShaderGUID, VFX_ITEM_TYPE_3D, Vector2, Vector3, Vector4, VertexAttribBuffer, WebGLHelper, WebHelper, createAnimationSampler, createPluginMaterial, fetchPBRShaderCode, fetchUnlitShaderCode, getDefaultEffectsGLTFLoader, getDefaultPBRMaterialData, getDefaultUnlitMaterialData, getDiffuseOnlyShaderCode, getGaussianBlurShaderCodeV1, getGaussianBlurShaderCodeV2, getGeometryDataFromOptions, getGeometryDataFromPropsList, getKawaseBlurShaderCode, getNormalVisShaderCode, getPBRPassShaderCode, getPBRShaderProperties, getPMeshList, getQuadFilterShaderCode, getRendererGPUInfo, getSceneManager, getShadowPassShaderCode, getSimpleFilterShaderCode, getSkyBoxShaderCode, getTransparecyBaseShader, getTransparecyFilterShader, getUnlitShaderProperties, setDefaultEffectsGLTFLoader, version };
13276
+ export { AnimationComponent, Box3, BoxMesh, CameraGestureHandlerImp, CameraGestureType, CheckerHelper, Color, CompositionCache, CompositionHitTest, DEG2RAD, Euler, EulerOrder, FBOOptions, Float16ArrayWrapper, GeometryBoxProxy, HitTestingProxy, HookOGLFunc, InterpolationSampler, JSONConverter, LoaderHelper, LoaderImpl, Matrix3, Matrix4, MeshHelper, ModelCameraComponent, ModelLightComponent, ModelMeshComponent, ModelPlugin, ModelPluginComponent, ModelSkyboxComponent, ModelTreeComponent, PAnimInterpType, PAnimPathType, PAnimTexture, PBRShaderGUID, PBlendMode, PCamera, PCameraManager, PCoordinate, PEntity, PFaceSideMode, PGeometry, PGlobalState, PLight, PLightManager, PLightType, PMaterialBase, PMaterialPBR, PMaterialSkyboxFilter, PMaterialType, PMaterialUnlit, PMesh, PMorph, PObject, PObjectType, PSceneManager, PShaderManager, PShadowType, PSkin, PSkybox, PSkyboxCreator, PSkyboxType, PSubMesh, PTextureType, PTransform, PluginHelper, Quaternion, Ray, RayBoxTesting, RayIntersectsBoxWithRotation, RayTriangleTesting, Sphere, TextureDataMode, ToggleItemBounding, TwoStatesSet, UnlitShaderGUID, VFX_ITEM_TYPE_3D, Vector2, Vector3, Vector4, VertexAttribBuffer, WebGLHelper, WebHelper, createAnimationSampler, createPluginMaterial, fetchPBRShaderCode, fetchUnlitShaderCode, getDefaultEffectsGLTFLoader, getDefaultPBRMaterialData, getDefaultUnlitMaterialData, getDiffuseOnlyShaderCode, getGaussianBlurShaderCodeV1, getGaussianBlurShaderCodeV2, getGeometryDataFromOptions, getGeometryDataFromPropsList, getKawaseBlurShaderCode, getNormalVisShaderCode, getPBRPassShaderCode, getPBRShaderProperties, getPMeshList, getQuadFilterShaderCode, getRendererGPUInfo, getSceneManager, getShadowPassShaderCode, getSimpleFilterShaderCode, getSkyBoxShaderCode, getTransparecyBaseShader, getTransparecyFilterShader, getUnlitShaderProperties, setDefaultEffectsGLTFLoader, version };
13781
13277
  //# sourceMappingURL=douyin.mjs.map