@galacean/effects-plugin-model 2.1.0-alpha.7 → 2.1.0-alpha.9
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/alipay.js +65 -598
- package/dist/alipay.js.map +1 -1
- package/dist/alipay.mjs +66 -594
- package/dist/alipay.mjs.map +1 -1
- package/dist/douyin.js +65 -598
- package/dist/douyin.js.map +1 -1
- package/dist/douyin.mjs +66 -594
- package/dist/douyin.mjs.map +1 -1
- package/dist/gltf/loader-impl.d.ts +6 -12
- package/dist/gltf/protocol.d.ts +2 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.js +66 -599
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +67 -595
- package/dist/index.mjs.map +1 -1
- package/dist/loader.mjs +66 -872
- package/dist/loader.mjs.map +1 -1
- package/dist/plugin/index.d.ts +1 -2
- package/dist/plugin/model-tree-component.d.ts +26 -0
- package/dist/runtime/animation.d.ts +0 -131
- package/dist/weapp.js +65 -598
- package/dist/weapp.js.map +1 -1
- package/dist/weapp.mjs +66 -594
- package/dist/weapp.mjs.map +1 -1
- package/package.json +4 -4
- package/dist/plugin/model-tree-item.d.ts +0 -132
- package/dist/plugin/model-tree-plugin.d.ts +0 -14
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Description: Galacean Effects player model plugin
|
|
4
4
|
* Author: Ant Group CO., Ltd.
|
|
5
5
|
* Contributors: 飂兮
|
|
6
|
-
* Version: v2.1.0-alpha.
|
|
6
|
+
* Version: v2.1.0-alpha.9
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -1511,144 +1511,6 @@ exports.PAnimPathType = void 0;
|
|
|
1511
1511
|
PAnimPathType[PAnimPathType["scale"] = 2] = "scale";
|
|
1512
1512
|
PAnimPathType[PAnimPathType["weights"] = 3] = "weights";
|
|
1513
1513
|
})(exports.PAnimPathType || (exports.PAnimPathType = {}));
|
|
1514
|
-
/**
|
|
1515
|
-
* 动画轨道类
|
|
1516
|
-
*/ var PAnimTrack = /*#__PURE__*/ function() {
|
|
1517
|
-
function PAnimTrack(options) {
|
|
1518
|
-
/**
|
|
1519
|
-
* 路径类型
|
|
1520
|
-
*/ this.path = 0;
|
|
1521
|
-
/**
|
|
1522
|
-
* 插值类型
|
|
1523
|
-
*/ this.interp = 0;
|
|
1524
|
-
var node = options.node, input = options.input, output = options.output, path = options.path, interpolation = options.interpolation;
|
|
1525
|
-
this.node = node;
|
|
1526
|
-
this.timeArray = input;
|
|
1527
|
-
this.dataArray = output;
|
|
1528
|
-
//
|
|
1529
|
-
if (path === "translation") {
|
|
1530
|
-
this.path = 0;
|
|
1531
|
-
this.component = 3;
|
|
1532
|
-
} else if (path === "rotation") {
|
|
1533
|
-
this.path = 1;
|
|
1534
|
-
this.component = 4;
|
|
1535
|
-
} else if (path === "scale") {
|
|
1536
|
-
this.path = 2;
|
|
1537
|
-
this.component = 3;
|
|
1538
|
-
} else if (path === "weights") {
|
|
1539
|
-
this.path = 3;
|
|
1540
|
-
this.component = this.dataArray.length / this.timeArray.length;
|
|
1541
|
-
// special checker for weights animation
|
|
1542
|
-
if (this.component <= 0) {
|
|
1543
|
-
console.error("Invalid weights component: " + this.timeArray.length + ", " + this.component + ", " + this.dataArray.length + ".");
|
|
1544
|
-
} else if (this.timeArray.length * this.component != this.dataArray.length) {
|
|
1545
|
-
console.error("Invalid weights array length: " + this.timeArray.length + ", " + this.component + ", " + this.dataArray.length + ".");
|
|
1546
|
-
}
|
|
1547
|
-
} else {
|
|
1548
|
-
// should never happened
|
|
1549
|
-
console.error("Invalid path status: " + path + ".");
|
|
1550
|
-
}
|
|
1551
|
-
if (this.timeArray.length * this.component > this.dataArray.length) {
|
|
1552
|
-
throw new Error("Data length mismatch: " + this.timeArray.length + ", " + this.component + ", " + this.dataArray.length + ".");
|
|
1553
|
-
}
|
|
1554
|
-
if (interpolation === "LINEAR") {
|
|
1555
|
-
this.interp = 0;
|
|
1556
|
-
} else if (interpolation === "STEP") {
|
|
1557
|
-
this.interp = 1;
|
|
1558
|
-
} else {
|
|
1559
|
-
this.interp = 2;
|
|
1560
|
-
}
|
|
1561
|
-
this.sampler = createAnimationSampler(this.getInterpInfo(), this.timeArray, this.dataArray, this.component, this.getPathInfo());
|
|
1562
|
-
}
|
|
1563
|
-
var _proto = PAnimTrack.prototype;
|
|
1564
|
-
/**
|
|
1565
|
-
* 销毁
|
|
1566
|
-
*/ _proto.dispose = function dispose() {
|
|
1567
|
-
var _this_sampler;
|
|
1568
|
-
// @ts-expect-error
|
|
1569
|
-
this.timeArray = undefined;
|
|
1570
|
-
// @ts-expect-error
|
|
1571
|
-
this.dataArray = undefined;
|
|
1572
|
-
(_this_sampler = this.sampler) == null ? void 0 : _this_sampler.dispose();
|
|
1573
|
-
this.sampler = undefined;
|
|
1574
|
-
};
|
|
1575
|
-
/**
|
|
1576
|
-
* 更新节点动画数据
|
|
1577
|
-
* @param time - 当前播放时间
|
|
1578
|
-
* @param treeItem - 节点树元素
|
|
1579
|
-
* @param sceneManager - 3D 场景管理器
|
|
1580
|
-
*/ _proto.tick = function tick(time, treeItem, sceneManager) {
|
|
1581
|
-
var _treeComponent_content;
|
|
1582
|
-
var treeComponent = treeItem.getComponent(exports.ModelTreeComponent);
|
|
1583
|
-
var node = treeComponent == null ? void 0 : (_treeComponent_content = treeComponent.content) == null ? void 0 : _treeComponent_content.getNodeById(this.node);
|
|
1584
|
-
if (this.sampler !== undefined && node !== undefined) {
|
|
1585
|
-
var result = this.sampler.evaluate(time);
|
|
1586
|
-
switch(this.path){
|
|
1587
|
-
case 0:
|
|
1588
|
-
node.transform.setPosition(result[0], result[1], result[2]);
|
|
1589
|
-
break;
|
|
1590
|
-
case 1:
|
|
1591
|
-
node.transform.setQuaternion(result[0], result[1], result[2], result[3]);
|
|
1592
|
-
break;
|
|
1593
|
-
case 2:
|
|
1594
|
-
node.transform.setScale(result[0], result[1], result[2]);
|
|
1595
|
-
break;
|
|
1596
|
-
case 3:
|
|
1597
|
-
{
|
|
1598
|
-
/**
|
|
1599
|
-
* 先生成Mesh的父节点id,然后通过id查询Mesh对象
|
|
1600
|
-
* 最后更新Mesh对象权重数据
|
|
1601
|
-
*/ var parentId = this.genParentId(treeItem.id, this.node);
|
|
1602
|
-
var mesh = sceneManager == null ? void 0 : sceneManager.queryMesh(parentId);
|
|
1603
|
-
if (mesh !== undefined) {
|
|
1604
|
-
mesh.updateMorphWeights(result);
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
break;
|
|
1608
|
-
}
|
|
1609
|
-
} else {
|
|
1610
|
-
if (this.sampler !== undefined) {
|
|
1611
|
-
console.error("AnimTrack: error", this.sampler, node);
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
};
|
|
1615
|
-
/**
|
|
1616
|
-
* 获取动画结束时间
|
|
1617
|
-
* @returns
|
|
1618
|
-
*/ _proto.getEndTime = function getEndTime() {
|
|
1619
|
-
var index = this.timeArray.length - 1;
|
|
1620
|
-
return this.timeArray[index];
|
|
1621
|
-
};
|
|
1622
|
-
/**
|
|
1623
|
-
* 生成 Mesh 元素的父节点
|
|
1624
|
-
*
|
|
1625
|
-
* @param parentId - 父节点 id 名称
|
|
1626
|
-
* @param nodeIndex - Mesh 节点索引
|
|
1627
|
-
*
|
|
1628
|
-
* @returns 生成的 Mesh 节点名称
|
|
1629
|
-
*/ _proto.genParentId = function genParentId(parentId, nodeIndex) {
|
|
1630
|
-
return parentId + "^" + nodeIndex;
|
|
1631
|
-
};
|
|
1632
|
-
_proto.getPathInfo = function getPathInfo() {
|
|
1633
|
-
if (this.path === 2) {
|
|
1634
|
-
return "scale";
|
|
1635
|
-
} else if (this.path === 1) {
|
|
1636
|
-
return "rotation";
|
|
1637
|
-
} else {
|
|
1638
|
-
return "translation";
|
|
1639
|
-
}
|
|
1640
|
-
};
|
|
1641
|
-
_proto.getInterpInfo = function getInterpInfo() {
|
|
1642
|
-
if (this.interp === 2) {
|
|
1643
|
-
return "CUBICSPLINE";
|
|
1644
|
-
} else if (this.interp === 1) {
|
|
1645
|
-
return "STEP";
|
|
1646
|
-
} else {
|
|
1647
|
-
return "LINEAR";
|
|
1648
|
-
}
|
|
1649
|
-
};
|
|
1650
|
-
return PAnimTrack;
|
|
1651
|
-
}();
|
|
1652
1514
|
/**
|
|
1653
1515
|
* 动画纹理类
|
|
1654
1516
|
*/ var PAnimTexture = /*#__PURE__*/ function() {
|
|
@@ -1735,148 +1597,6 @@ exports.PAnimPathType = void 0;
|
|
|
1735
1597
|
};
|
|
1736
1598
|
return PAnimTexture;
|
|
1737
1599
|
}();
|
|
1738
|
-
/**
|
|
1739
|
-
* 动画类,负责动画数据创建、更新和销毁
|
|
1740
|
-
*/ var PAnimation = /*#__PURE__*/ function(PObject) {
|
|
1741
|
-
_inherits(PAnimation, PObject);
|
|
1742
|
-
function PAnimation() {
|
|
1743
|
-
var _this;
|
|
1744
|
-
_this = PObject.apply(this, arguments) || this;
|
|
1745
|
-
_this.time = 0;
|
|
1746
|
-
_this.duration = 0;
|
|
1747
|
-
_this.tracks = [];
|
|
1748
|
-
return _this;
|
|
1749
|
-
}
|
|
1750
|
-
var _proto = PAnimation.prototype;
|
|
1751
|
-
/**
|
|
1752
|
-
* 创建动画对象
|
|
1753
|
-
* @param options - 动画参数
|
|
1754
|
-
*/ _proto.create = function create(options) {
|
|
1755
|
-
var _this = this;
|
|
1756
|
-
var _options_name;
|
|
1757
|
-
this.name = this.genName((_options_name = options.name) != null ? _options_name : "Unnamed animation");
|
|
1758
|
-
this.type = exports.PObjectType.animation;
|
|
1759
|
-
//
|
|
1760
|
-
this.time = 0;
|
|
1761
|
-
this.duration = 0;
|
|
1762
|
-
//
|
|
1763
|
-
this.tracks = [];
|
|
1764
|
-
options.tracks.forEach(function(inTrack) {
|
|
1765
|
-
var track = new PAnimTrack(inTrack);
|
|
1766
|
-
_this.tracks.push(track);
|
|
1767
|
-
_this.duration = Math.max(_this.duration, track.getEndTime());
|
|
1768
|
-
});
|
|
1769
|
-
};
|
|
1770
|
-
/**
|
|
1771
|
-
* 动画更新
|
|
1772
|
-
* @param time - 当前时间
|
|
1773
|
-
* @param treeItem - 场景树元素
|
|
1774
|
-
* @param sceneManager - 3D 场景管理器
|
|
1775
|
-
*/ _proto.tick = function tick(time, treeItem, sceneManager) {
|
|
1776
|
-
this.time = time;
|
|
1777
|
-
// TODO: 这里时间事件定义不明确,先兼容原先实现
|
|
1778
|
-
var newTime = this.time % this.duration;
|
|
1779
|
-
this.tracks.forEach(function(track) {
|
|
1780
|
-
track.tick(newTime, treeItem, sceneManager);
|
|
1781
|
-
});
|
|
1782
|
-
};
|
|
1783
|
-
/**
|
|
1784
|
-
* 销毁
|
|
1785
|
-
*/ _proto.dispose = function dispose() {
|
|
1786
|
-
this.tracks.forEach(function(track) {
|
|
1787
|
-
track.dispose();
|
|
1788
|
-
});
|
|
1789
|
-
this.tracks = [];
|
|
1790
|
-
};
|
|
1791
|
-
return PAnimation;
|
|
1792
|
-
}(PObject);
|
|
1793
|
-
/**
|
|
1794
|
-
* 动画管理类,负责管理动画对象
|
|
1795
|
-
*/ var PAnimationManager = /*#__PURE__*/ function(PObject) {
|
|
1796
|
-
_inherits(PAnimationManager, PObject);
|
|
1797
|
-
function PAnimationManager(treeOptions, ownerItem) {
|
|
1798
|
-
var _this;
|
|
1799
|
-
_this = PObject.call(this) || this;
|
|
1800
|
-
_this.animation = 0;
|
|
1801
|
-
_this.speed = 0;
|
|
1802
|
-
_this.delay = 0;
|
|
1803
|
-
_this.time = 0;
|
|
1804
|
-
_this.animations = [];
|
|
1805
|
-
var _ownerItem_name;
|
|
1806
|
-
_this.name = _this.genName((_ownerItem_name = ownerItem.name) != null ? _ownerItem_name : "Unnamed tree");
|
|
1807
|
-
_this.type = exports.PObjectType.animationManager;
|
|
1808
|
-
//
|
|
1809
|
-
_this.ownerItem = ownerItem;
|
|
1810
|
-
var _treeOptions_animation;
|
|
1811
|
-
_this.animation = (_treeOptions_animation = treeOptions.animation) != null ? _treeOptions_animation : -1;
|
|
1812
|
-
_this.speed = 1.0;
|
|
1813
|
-
var _ownerItem_start;
|
|
1814
|
-
_this.delay = (_ownerItem_start = ownerItem.start) != null ? _ownerItem_start : 0;
|
|
1815
|
-
_this.animations = [];
|
|
1816
|
-
if (treeOptions.animations !== undefined) {
|
|
1817
|
-
treeOptions.animations.forEach(function(animOpts) {
|
|
1818
|
-
var anim = _this.createAnimation(animOpts);
|
|
1819
|
-
_this.animations.push(anim);
|
|
1820
|
-
});
|
|
1821
|
-
}
|
|
1822
|
-
return _this;
|
|
1823
|
-
}
|
|
1824
|
-
var _proto = PAnimationManager.prototype;
|
|
1825
|
-
/**
|
|
1826
|
-
* 设置场景管理器
|
|
1827
|
-
* @param sceneManager - 场景管理器
|
|
1828
|
-
*/ _proto.setSceneManager = function setSceneManager(sceneManager) {
|
|
1829
|
-
this.sceneManager = sceneManager;
|
|
1830
|
-
};
|
|
1831
|
-
/**
|
|
1832
|
-
* 创建动画对象
|
|
1833
|
-
* @param animationOpts - 动画参数
|
|
1834
|
-
* @returns 动画对象
|
|
1835
|
-
*/ _proto.createAnimation = function createAnimation(animationOpts) {
|
|
1836
|
-
var animation = new PAnimation();
|
|
1837
|
-
animation.create(animationOpts);
|
|
1838
|
-
return animation;
|
|
1839
|
-
};
|
|
1840
|
-
/**
|
|
1841
|
-
* 动画更新
|
|
1842
|
-
* @param deltaSeconds - 更新间隔
|
|
1843
|
-
*/ _proto.tick = function tick(deltaSeconds) {
|
|
1844
|
-
var _this = this;
|
|
1845
|
-
var newDeltaSeconds = deltaSeconds * this.speed * 0.001;
|
|
1846
|
-
this.time += newDeltaSeconds;
|
|
1847
|
-
// TODO: 需要合并到TreeItem中,通过lifetime进行计算
|
|
1848
|
-
var itemTime = this.time - this.delay;
|
|
1849
|
-
if (itemTime >= 0) {
|
|
1850
|
-
if (this.animation >= 0 && this.animation < this.animations.length) {
|
|
1851
|
-
var anim = this.animations[this.animation];
|
|
1852
|
-
anim.tick(itemTime, this.ownerItem, this.sceneManager);
|
|
1853
|
-
} else if (this.animation == -88888888) {
|
|
1854
|
-
this.animations.forEach(function(anim) {
|
|
1855
|
-
anim.tick(itemTime, _this.ownerItem, _this.sceneManager);
|
|
1856
|
-
});
|
|
1857
|
-
}
|
|
1858
|
-
}
|
|
1859
|
-
};
|
|
1860
|
-
/**
|
|
1861
|
-
* 销毁
|
|
1862
|
-
*/ _proto.dispose = function dispose() {
|
|
1863
|
-
// @ts-expect-error
|
|
1864
|
-
this.ownerItem = null;
|
|
1865
|
-
this.animations.forEach(function(anim) {
|
|
1866
|
-
anim.dispose();
|
|
1867
|
-
});
|
|
1868
|
-
this.animations = [];
|
|
1869
|
-
// @ts-expect-error
|
|
1870
|
-
this.sceneManager = null;
|
|
1871
|
-
};
|
|
1872
|
-
/**
|
|
1873
|
-
* 获取场景树元素
|
|
1874
|
-
* @returns
|
|
1875
|
-
*/ _proto.getTreeItem = function getTreeItem() {
|
|
1876
|
-
return this.ownerItem;
|
|
1877
|
-
};
|
|
1878
|
-
return PAnimationManager;
|
|
1879
|
-
}(PObject);
|
|
1880
1600
|
|
|
1881
1601
|
var deg2rad = Math.PI / 180;
|
|
1882
1602
|
/**
|
|
@@ -3526,15 +3246,6 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
|
|
|
3526
3246
|
_proto.isHide = function isHide() {
|
|
3527
3247
|
return this.data.hide === true;
|
|
3528
3248
|
};
|
|
3529
|
-
_proto.getParentNode = function getParentNode() {
|
|
3530
|
-
var _this_parentItem;
|
|
3531
|
-
var nodeIndex = this.getParentIndex();
|
|
3532
|
-
var parentTree = (_this_parentItem = this.parentItem) == null ? void 0 : _this_parentItem.getComponent(exports.ModelTreeComponent);
|
|
3533
|
-
if (parentTree !== undefined && nodeIndex >= 0) {
|
|
3534
|
-
return parentTree.content.getNodeById(nodeIndex);
|
|
3535
|
-
}
|
|
3536
|
-
return undefined;
|
|
3537
|
-
};
|
|
3538
3249
|
_proto.getParentIndex = function getParentIndex() {
|
|
3539
3250
|
return -1;
|
|
3540
3251
|
};
|
|
@@ -3972,7 +3683,7 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
|
|
|
3972
3683
|
|
|
3973
3684
|
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}";
|
|
3974
3685
|
|
|
3975
|
-
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\nvec3 newBaseColor=vec3(dot(_BaseColorFactor.xyz,vec3(0.3)));MaterialInfo diffuseMaterialInfo=MaterialInfo(1.0,vec3(0.0),1.0,newBaseColor,vec3(0.0),vec3(0.0));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#endif\ngl_FragColor.rgb=toneMap(debugDiffuse);\n#endif\ngl_FragColor.a=1.0;\n#endif\n}";
|
|
3686
|
+
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}";
|
|
3976
3687
|
|
|
3977
3688
|
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}";
|
|
3978
3689
|
|
|
@@ -6205,31 +5916,6 @@ var normal = new Vector3();
|
|
|
6205
5916
|
console.error("setupItem3DOptions: Invalid inverseBindMatrices type, " + inverseBindMatrices + ".");
|
|
6206
5917
|
}
|
|
6207
5918
|
}
|
|
6208
|
-
} else if (item.type === EFFECTS.spec.ItemType.tree) {
|
|
6209
|
-
var jsonItem = item;
|
|
6210
|
-
var studioItem = item;
|
|
6211
|
-
var jsonAnimations = jsonItem.content.options.tree.animations;
|
|
6212
|
-
var studioAnimations = studioItem.content.options.tree.animations;
|
|
6213
|
-
if (jsonAnimations !== undefined && studioAnimations !== undefined) {
|
|
6214
|
-
jsonAnimations.forEach(function(jsonAnim, i) {
|
|
6215
|
-
var studioAnim = studioAnimations[i];
|
|
6216
|
-
jsonAnim.tracks.forEach(function(jsonTrack, j) {
|
|
6217
|
-
var inputArray = typedArrayFromBinary(scene.bins, jsonTrack.input);
|
|
6218
|
-
var outputArray = typedArrayFromBinary(scene.bins, jsonTrack.output);
|
|
6219
|
-
var studioTrack = studioAnim.tracks[j];
|
|
6220
|
-
if (_instanceof1(inputArray, Float32Array)) {
|
|
6221
|
-
studioTrack.input = inputArray;
|
|
6222
|
-
} else {
|
|
6223
|
-
console.error("setupItem3DOptions: Type of inputArray should be float32, " + inputArray + ".");
|
|
6224
|
-
}
|
|
6225
|
-
if (_instanceof1(outputArray, Float32Array)) {
|
|
6226
|
-
studioTrack.output = outputArray;
|
|
6227
|
-
} else {
|
|
6228
|
-
console.error("setupItem3DOptions: Type of outputArray should be float32, " + outputArray + ".");
|
|
6229
|
-
}
|
|
6230
|
-
});
|
|
6231
|
-
});
|
|
6232
|
-
}
|
|
6233
5919
|
} else if (item.type === EFFECTS.spec.ItemType.skybox) {
|
|
6234
5920
|
var skybox = item;
|
|
6235
5921
|
var studioSkybox = item;
|
|
@@ -9952,117 +9638,6 @@ exports.ModelPluginComponent = __decorate([
|
|
|
9952
9638
|
return pluginComp == null ? void 0 : pluginComp.scene;
|
|
9953
9639
|
}
|
|
9954
9640
|
|
|
9955
|
-
/**
|
|
9956
|
-
* 场景树元素类,支持插件中节点树相关的动画能力
|
|
9957
|
-
*/ var ModelTreeItem = /*#__PURE__*/ function() {
|
|
9958
|
-
function ModelTreeItem(props, owner) {
|
|
9959
|
-
this.baseTransform = owner.transform;
|
|
9960
|
-
this.animationManager = new PAnimationManager(props, owner);
|
|
9961
|
-
this.build(props);
|
|
9962
|
-
}
|
|
9963
|
-
var _proto = ModelTreeItem.prototype;
|
|
9964
|
-
/**
|
|
9965
|
-
* 场景树更新,主要是动画更新
|
|
9966
|
-
* @param dt - 时间间隔
|
|
9967
|
-
*/ _proto.tick = function tick(dt) {
|
|
9968
|
-
this.animationManager.tick(dt);
|
|
9969
|
-
};
|
|
9970
|
-
/**
|
|
9971
|
-
* 获取所有节点
|
|
9972
|
-
* @returns
|
|
9973
|
-
*/ _proto.getNodes = function getNodes() {
|
|
9974
|
-
return this.nodes;
|
|
9975
|
-
};
|
|
9976
|
-
/**
|
|
9977
|
-
* 根据节点编号,查询节点
|
|
9978
|
-
* @param nodeId - 节点编号
|
|
9979
|
-
* @returns
|
|
9980
|
-
*/ _proto.getNodeById = function getNodeById(nodeId) {
|
|
9981
|
-
var cache = this.cacheMap;
|
|
9982
|
-
if (!cache[nodeId]) {
|
|
9983
|
-
var index = "^" + nodeId;
|
|
9984
|
-
// @ts-expect-error
|
|
9985
|
-
cache[nodeId] = this.allNodes.find(function(node) {
|
|
9986
|
-
return node.id === index;
|
|
9987
|
-
});
|
|
9988
|
-
}
|
|
9989
|
-
return cache[nodeId];
|
|
9990
|
-
};
|
|
9991
|
-
/**
|
|
9992
|
-
* 根据节点名称,查询节点
|
|
9993
|
-
* @param name - 名称
|
|
9994
|
-
* @returns
|
|
9995
|
-
*/ _proto.getNodeByName = function getNodeByName(name) {
|
|
9996
|
-
var cache = this.cacheMap;
|
|
9997
|
-
if (!cache[name]) {
|
|
9998
|
-
// @ts-expect-error
|
|
9999
|
-
cache[name] = this.allNodes.find(function(node) {
|
|
10000
|
-
return node.name === name;
|
|
10001
|
-
});
|
|
10002
|
-
}
|
|
10003
|
-
return cache[name];
|
|
10004
|
-
};
|
|
10005
|
-
/**
|
|
10006
|
-
* 根据节点 id 查询节点变换,如果查询不到节点就直接返回基础变换
|
|
10007
|
-
* @param nodeId - 节点 id
|
|
10008
|
-
* @returns
|
|
10009
|
-
*/ _proto.getNodeTransform = function getNodeTransform(nodeId) {
|
|
10010
|
-
var node = this.getNodeById(nodeId);
|
|
10011
|
-
return node ? node.transform : this.baseTransform;
|
|
10012
|
-
};
|
|
10013
|
-
/**
|
|
10014
|
-
* 销毁场景树对象
|
|
10015
|
-
*/ _proto.dispose = function dispose() {
|
|
10016
|
-
var _this_animationManager;
|
|
10017
|
-
this.allNodes = [];
|
|
10018
|
-
this.nodes = [];
|
|
10019
|
-
this.cacheMap = {};
|
|
10020
|
-
// @ts-expect-error
|
|
10021
|
-
this.baseTransform = null;
|
|
10022
|
-
(_this_animationManager = this.animationManager) == null ? void 0 : _this_animationManager.dispose();
|
|
10023
|
-
// @ts-expect-error
|
|
10024
|
-
this.animationManager = null;
|
|
10025
|
-
};
|
|
10026
|
-
_proto.build = function build(options) {
|
|
10027
|
-
var _this = this;
|
|
10028
|
-
var topTransform = this.baseTransform;
|
|
10029
|
-
var nodes = options.nodes.map(function(node, i) {
|
|
10030
|
-
return {
|
|
10031
|
-
name: node.name || node.id || i + "",
|
|
10032
|
-
transform: new EFFECTS.Transform(_extends({}, node.transform, {
|
|
10033
|
-
valid: true
|
|
10034
|
-
}), topTransform),
|
|
10035
|
-
id: "^" + (node.id || i),
|
|
10036
|
-
children: [],
|
|
10037
|
-
tree: _this
|
|
10038
|
-
};
|
|
10039
|
-
});
|
|
10040
|
-
this.cacheMap = {};
|
|
10041
|
-
nodes.forEach(function(node, i) {
|
|
10042
|
-
var children = options.nodes[i].children;
|
|
10043
|
-
// @ts-expect-error
|
|
10044
|
-
node.transform.name = node.name;
|
|
10045
|
-
node.transform.setValid(true);
|
|
10046
|
-
if (children) {
|
|
10047
|
-
children.forEach(function(index) {
|
|
10048
|
-
var child = nodes[index];
|
|
10049
|
-
if (child && child !== node) {
|
|
10050
|
-
if (child.transform.parentTransform !== topTransform) {
|
|
10051
|
-
console.error("Node parent has been set.");
|
|
10052
|
-
}
|
|
10053
|
-
child.transform.parentTransform = node.transform;
|
|
10054
|
-
node.children.push(child);
|
|
10055
|
-
}
|
|
10056
|
-
});
|
|
10057
|
-
}
|
|
10058
|
-
});
|
|
10059
|
-
this.allNodes = nodes;
|
|
10060
|
-
this.nodes = options.children.map(function(i) {
|
|
10061
|
-
return nodes[i];
|
|
10062
|
-
});
|
|
10063
|
-
};
|
|
10064
|
-
return ModelTreeItem;
|
|
10065
|
-
}();
|
|
10066
9641
|
exports.ModelTreeComponent = /*#__PURE__*/ function(Behaviour) {
|
|
10067
9642
|
_inherits(ModelTreeComponent, Behaviour);
|
|
10068
9643
|
function ModelTreeComponent(engine, options) {
|
|
@@ -10080,56 +9655,6 @@ exports.ModelTreeComponent = /*#__PURE__*/ function(Behaviour) {
|
|
|
10080
9655
|
*/ _proto.fromData = function fromData(options) {
|
|
10081
9656
|
Behaviour.prototype.fromData.call(this, options);
|
|
10082
9657
|
this.options = options;
|
|
10083
|
-
this.createContent();
|
|
10084
|
-
};
|
|
10085
|
-
/**
|
|
10086
|
-
* 组件开始,查询合成中场景管理器并设置到动画管理器中
|
|
10087
|
-
*/ _proto.onStart = function onStart() {
|
|
10088
|
-
this.item.type = EFFECTS.spec.ItemType.tree;
|
|
10089
|
-
this.content.baseTransform.setValid(true);
|
|
10090
|
-
var sceneManager = getSceneManager(this);
|
|
10091
|
-
if (sceneManager) {
|
|
10092
|
-
this.content.animationManager.setSceneManager(sceneManager);
|
|
10093
|
-
}
|
|
10094
|
-
};
|
|
10095
|
-
/**
|
|
10096
|
-
* 组件更新,内部对象更新
|
|
10097
|
-
* @param dt
|
|
10098
|
-
*/ _proto.onUpdate = function onUpdate(dt) {
|
|
10099
|
-
var // this.timeline?.getRenderData(time, true);
|
|
10100
|
-
// TODO: 需要使用lifetime
|
|
10101
|
-
_this_content;
|
|
10102
|
-
(_this_content = this.content) == null ? void 0 : _this_content.tick(dt);
|
|
10103
|
-
};
|
|
10104
|
-
/**
|
|
10105
|
-
* 组件销毁,内部对象销毁
|
|
10106
|
-
*/ _proto.onDestroy = function onDestroy() {
|
|
10107
|
-
var _this_content;
|
|
10108
|
-
(_this_content = this.content) == null ? void 0 : _this_content.dispose();
|
|
10109
|
-
};
|
|
10110
|
-
/**
|
|
10111
|
-
* 创建内部场景树元素
|
|
10112
|
-
*/ _proto.createContent = function createContent() {
|
|
10113
|
-
if (this.options) {
|
|
10114
|
-
var treeOptions = this.options.options.tree;
|
|
10115
|
-
this.content = new ModelTreeItem(treeOptions, this.item);
|
|
10116
|
-
}
|
|
10117
|
-
};
|
|
10118
|
-
/**
|
|
10119
|
-
* 获取元素的变换
|
|
10120
|
-
* @param itemId - 元素索引
|
|
10121
|
-
* @returns
|
|
10122
|
-
*/ _proto.getNodeTransform = function getNodeTransform(itemId) {
|
|
10123
|
-
if (this.content === undefined) {
|
|
10124
|
-
return this.transform;
|
|
10125
|
-
}
|
|
10126
|
-
var idWithSubfix = this.item.id + "^";
|
|
10127
|
-
if (itemId.indexOf(idWithSubfix) === 0) {
|
|
10128
|
-
var nodeId = itemId.substring(idWithSubfix.length);
|
|
10129
|
-
return this.content.getNodeTransform(nodeId);
|
|
10130
|
-
} else {
|
|
10131
|
-
return this.transform;
|
|
10132
|
-
}
|
|
10133
9658
|
};
|
|
10134
9659
|
return ModelTreeComponent;
|
|
10135
9660
|
}(EFFECTS.Behaviour);
|
|
@@ -10137,24 +9662,6 @@ exports.ModelTreeComponent = __decorate([
|
|
|
10137
9662
|
EFFECTS.effectsClass(EFFECTS.spec.DataType.TreeComponent)
|
|
10138
9663
|
], exports.ModelTreeComponent);
|
|
10139
9664
|
|
|
10140
|
-
/**
|
|
10141
|
-
* 场景树插件类,支持 3D 相关的节点动画和骨骼动画等
|
|
10142
|
-
*/ var ModelTreePlugin = /*#__PURE__*/ function(AbstractPlugin) {
|
|
10143
|
-
_inherits(ModelTreePlugin, AbstractPlugin);
|
|
10144
|
-
function ModelTreePlugin() {
|
|
10145
|
-
var _this;
|
|
10146
|
-
_this = AbstractPlugin.apply(this, arguments) || this;
|
|
10147
|
-
/**
|
|
10148
|
-
* 插件名称
|
|
10149
|
-
*/ _this.name = "tree";
|
|
10150
|
-
/**
|
|
10151
|
-
* 高优先级更新
|
|
10152
|
-
*/ _this.order = 2;
|
|
10153
|
-
return _this;
|
|
10154
|
-
}
|
|
10155
|
-
return ModelTreePlugin;
|
|
10156
|
-
}(EFFECTS.AbstractPlugin);
|
|
10157
|
-
|
|
10158
9665
|
exports.CameraGestureType = void 0;
|
|
10159
9666
|
(function(CameraGestureType) {
|
|
10160
9667
|
CameraGestureType[CameraGestureType["none"] = 0] = "none";
|
|
@@ -10692,7 +10199,7 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
10692
10199
|
_proto.processScene = function processScene(sceneData) {
|
|
10693
10200
|
var _this = this;
|
|
10694
10201
|
return _async_to_generator(function() {
|
|
10695
|
-
var sceneJSON, _tmp, oldScene, _oldScene_bins, oldBinUrls, binFiles, _iterator, _step, bin, _, newScene;
|
|
10202
|
+
var sceneJSON, _tmp, oldScene, _oldScene_bins, oldBinUrls, binFiles, v, _iterator, _step, bin, _, newScene;
|
|
10696
10203
|
return __generator(this, function(_state) {
|
|
10697
10204
|
switch(_state.label){
|
|
10698
10205
|
case 0:
|
|
@@ -10729,6 +10236,14 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
10729
10236
|
oldScene = EFFECTS.getStandardJSON(sceneJSON);
|
|
10730
10237
|
oldBinUrls = (_oldScene_bins = oldScene.bins) != null ? _oldScene_bins : [];
|
|
10731
10238
|
binFiles = [];
|
|
10239
|
+
//@ts-expect-error
|
|
10240
|
+
v = sceneJSON.version.split(".");
|
|
10241
|
+
if (Number(v[0]) >= 3) {
|
|
10242
|
+
return [
|
|
10243
|
+
2,
|
|
10244
|
+
oldScene
|
|
10245
|
+
];
|
|
10246
|
+
}
|
|
10732
10247
|
if (!oldScene.bins) return [
|
|
10733
10248
|
3,
|
|
10734
10249
|
7
|
|
@@ -10928,7 +10443,6 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
10928
10443
|
this.createItemsFromTreeComponent(comp, newScene, oldScene);
|
|
10929
10444
|
treeComp.options.tree.animation = undefined;
|
|
10930
10445
|
treeComp.options.tree.animations = undefined;
|
|
10931
|
-
newComponents.push(comp);
|
|
10932
10446
|
} else if (comp.dataType !== EFFECTS.spec.DataType.MeshComponent) {
|
|
10933
10447
|
newComponents.push(comp);
|
|
10934
10448
|
}
|
|
@@ -11366,6 +10880,7 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
11366
10880
|
});
|
|
11367
10881
|
});
|
|
11368
10882
|
}
|
|
10883
|
+
treeItem.components = [];
|
|
11369
10884
|
treeItem.components.push({
|
|
11370
10885
|
id: animationComponent.id
|
|
11371
10886
|
});
|
|
@@ -12703,6 +12218,59 @@ var LoaderImpl = /*#__PURE__*/ function() {
|
|
|
12703
12218
|
this.items.push(item);
|
|
12704
12219
|
this.components.push(component);
|
|
12705
12220
|
};
|
|
12221
|
+
_proto.addSkybox = function addSkybox(skybox) {
|
|
12222
|
+
var _this_images, // @ts-expect-error
|
|
12223
|
+
_this_textures;
|
|
12224
|
+
var itemId = EFFECTS.generateGUID();
|
|
12225
|
+
var skyboxInfo = PSkyboxCreator.createSkyboxComponentData(skybox);
|
|
12226
|
+
var imageList = skyboxInfo.imageList, textureOptionsList = skyboxInfo.textureOptionsList, component = skyboxInfo.component;
|
|
12227
|
+
component.item.id = itemId;
|
|
12228
|
+
if (skybox.intensity !== undefined) {
|
|
12229
|
+
component.intensity = skybox.intensity;
|
|
12230
|
+
}
|
|
12231
|
+
if (skybox.reflectionsIntensity !== undefined) {
|
|
12232
|
+
component.reflectionsIntensity = skybox.reflectionsIntensity;
|
|
12233
|
+
}
|
|
12234
|
+
var _skybox_renderable;
|
|
12235
|
+
component.renderable = (_skybox_renderable = skybox.renderable) != null ? _skybox_renderable : false;
|
|
12236
|
+
var item = {
|
|
12237
|
+
id: itemId,
|
|
12238
|
+
name: "Skybox-Customize",
|
|
12239
|
+
duration: 999,
|
|
12240
|
+
type: EFFECTS.spec.ItemType.skybox,
|
|
12241
|
+
pn: 0,
|
|
12242
|
+
visible: true,
|
|
12243
|
+
endBehavior: EFFECTS.spec.EndBehavior.freeze,
|
|
12244
|
+
transform: {
|
|
12245
|
+
position: {
|
|
12246
|
+
x: 0,
|
|
12247
|
+
y: 0,
|
|
12248
|
+
z: 0
|
|
12249
|
+
},
|
|
12250
|
+
eulerHint: {
|
|
12251
|
+
x: 0,
|
|
12252
|
+
y: 0,
|
|
12253
|
+
z: 0
|
|
12254
|
+
},
|
|
12255
|
+
scale: {
|
|
12256
|
+
x: 1,
|
|
12257
|
+
y: 1,
|
|
12258
|
+
z: 1
|
|
12259
|
+
}
|
|
12260
|
+
},
|
|
12261
|
+
components: [
|
|
12262
|
+
{
|
|
12263
|
+
id: component.id
|
|
12264
|
+
}
|
|
12265
|
+
],
|
|
12266
|
+
content: {},
|
|
12267
|
+
dataType: EFFECTS.spec.DataType.VFXItemData
|
|
12268
|
+
};
|
|
12269
|
+
(_this_images = this.images).push.apply(_this_images, [].concat(imageList));
|
|
12270
|
+
(_this_textures = this.textures).push.apply(_this_textures, [].concat(textureOptionsList));
|
|
12271
|
+
this.items.push(item);
|
|
12272
|
+
this.components.push(component);
|
|
12273
|
+
};
|
|
12706
12274
|
_proto.tryAddSkybox = function tryAddSkybox(skybox) {
|
|
12707
12275
|
var _this = this;
|
|
12708
12276
|
return _async_to_generator(function() {
|
|
@@ -12837,43 +12405,6 @@ var LoaderImpl = /*#__PURE__*/ function() {
|
|
|
12837
12405
|
});
|
|
12838
12406
|
return sceneAABB;
|
|
12839
12407
|
};
|
|
12840
|
-
/**
|
|
12841
|
-
* 按照传入的动画播放参数,计算需要播放的动画索引
|
|
12842
|
-
*
|
|
12843
|
-
* @param treeOptions 节点树属性,需要初始化animations列表。
|
|
12844
|
-
* @returns 返回计算的动画索引,-1表示没有动画需要播放,-88888888表示播放所有动画。
|
|
12845
|
-
*/ _proto.getPlayAnimationIndex = function getPlayAnimationIndex(treeOptions) {
|
|
12846
|
-
var animations = treeOptions.animations;
|
|
12847
|
-
if (animations === undefined || animations.length <= 0) {
|
|
12848
|
-
// 硬编码,内部指定的不播放动画的索引值
|
|
12849
|
-
return -1;
|
|
12850
|
-
}
|
|
12851
|
-
if (this.isPlayAllAnimation()) {
|
|
12852
|
-
// 硬编码,内部指定的播放全部动画的索引值
|
|
12853
|
-
return -88888888;
|
|
12854
|
-
}
|
|
12855
|
-
var animationInfo = this.sceneOptions.effects.playAnimation;
|
|
12856
|
-
if (animationInfo === undefined) {
|
|
12857
|
-
return -1;
|
|
12858
|
-
}
|
|
12859
|
-
if (typeof animationInfo === "number") {
|
|
12860
|
-
if (animationInfo >= 0 && animationInfo < animations.length) {
|
|
12861
|
-
return animationInfo;
|
|
12862
|
-
} else {
|
|
12863
|
-
return -1;
|
|
12864
|
-
}
|
|
12865
|
-
} else {
|
|
12866
|
-
// typeof animationInfo === 'string'
|
|
12867
|
-
var animationIndex = -1;
|
|
12868
|
-
// 通过动画名字查找动画索引
|
|
12869
|
-
animations.forEach(function(anim, index) {
|
|
12870
|
-
if (anim.name === animationInfo) {
|
|
12871
|
-
animationIndex = index;
|
|
12872
|
-
}
|
|
12873
|
-
});
|
|
12874
|
-
return animationIndex;
|
|
12875
|
-
}
|
|
12876
|
-
};
|
|
12877
12408
|
_proto.isPlayAnimation = function isPlayAnimation() {
|
|
12878
12409
|
return this.sceneOptions.effects.playAnimation !== undefined;
|
|
12879
12410
|
};
|
|
@@ -13015,64 +12546,6 @@ var LoaderImpl = /*#__PURE__*/ function() {
|
|
|
13015
12546
|
}
|
|
13016
12547
|
});
|
|
13017
12548
|
};
|
|
13018
|
-
_proto.createTreeOptions = function createTreeOptions(scene) {
|
|
13019
|
-
var nodeList = scene.nodes.map(function(node, nodeIndex) {
|
|
13020
|
-
var children = node.children.map(function(child) {
|
|
13021
|
-
if (child.nodeIndex === undefined) {
|
|
13022
|
-
throw new Error("Undefined nodeIndex for child " + child);
|
|
13023
|
-
}
|
|
13024
|
-
return child.nodeIndex;
|
|
13025
|
-
});
|
|
13026
|
-
var pos;
|
|
13027
|
-
var quat;
|
|
13028
|
-
var scale;
|
|
13029
|
-
if (node.matrix !== undefined) {
|
|
13030
|
-
if (node.matrix.length !== 16) {
|
|
13031
|
-
throw new Error("Invalid matrix length " + node.matrix.length + " for node " + node);
|
|
13032
|
-
}
|
|
13033
|
-
var mat = Matrix4.fromArray(node.matrix);
|
|
13034
|
-
var transform = mat.getTransform();
|
|
13035
|
-
pos = transform.translation.toArray();
|
|
13036
|
-
quat = transform.rotation.toArray();
|
|
13037
|
-
scale = transform.scale.toArray();
|
|
13038
|
-
} else {
|
|
13039
|
-
if (node.translation !== undefined) {
|
|
13040
|
-
pos = node.translation;
|
|
13041
|
-
}
|
|
13042
|
-
if (node.rotation !== undefined) {
|
|
13043
|
-
quat = node.rotation;
|
|
13044
|
-
}
|
|
13045
|
-
if (node.scale !== undefined) {
|
|
13046
|
-
scale = node.scale;
|
|
13047
|
-
}
|
|
13048
|
-
}
|
|
13049
|
-
node.nodeIndex = nodeIndex;
|
|
13050
|
-
var treeNode = {
|
|
13051
|
-
name: node.name,
|
|
13052
|
-
transform: {
|
|
13053
|
-
position: pos,
|
|
13054
|
-
quat: quat,
|
|
13055
|
-
scale: scale
|
|
13056
|
-
},
|
|
13057
|
-
children: children,
|
|
13058
|
-
id: "" + node.nodeIndex
|
|
13059
|
-
};
|
|
13060
|
-
return treeNode;
|
|
13061
|
-
});
|
|
13062
|
-
var rootNodes = scene.rootNodes.map(function(root) {
|
|
13063
|
-
if (root.nodeIndex === undefined) {
|
|
13064
|
-
throw new Error("Undefined nodeIndex for root " + root);
|
|
13065
|
-
}
|
|
13066
|
-
return root.nodeIndex;
|
|
13067
|
-
});
|
|
13068
|
-
var treeOptions = {
|
|
13069
|
-
nodes: nodeList,
|
|
13070
|
-
children: rootNodes,
|
|
13071
|
-
animation: -1,
|
|
13072
|
-
animations: []
|
|
13073
|
-
};
|
|
13074
|
-
return treeOptions;
|
|
13075
|
-
};
|
|
13076
12549
|
_proto.createAnimations = function createAnimations(animations) {
|
|
13077
12550
|
return animations.map(function(anim) {
|
|
13078
12551
|
var tracks = anim.channels.map(function(channel) {
|
|
@@ -13822,9 +13295,8 @@ var GLTFHelper = /*#__PURE__*/ function() {
|
|
|
13822
13295
|
return GLTFHelper;
|
|
13823
13296
|
}();
|
|
13824
13297
|
|
|
13825
|
-
EFFECTS.registerPlugin("tree", ModelTreePlugin, EFFECTS.VFXItem, true);
|
|
13826
13298
|
EFFECTS.registerPlugin("model", ModelPlugin, EFFECTS.VFXItem);
|
|
13827
|
-
var version = "2.1.0-alpha.
|
|
13299
|
+
var version = "2.1.0-alpha.9";
|
|
13828
13300
|
EFFECTS.logger.info("Plugin model version: " + version + ".");
|
|
13829
13301
|
if (version !== EFFECTS__namespace.version) {
|
|
13830
13302
|
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!");
|
|
@@ -13853,12 +13325,7 @@ exports.Matrix3 = Matrix3;
|
|
|
13853
13325
|
exports.Matrix4 = Matrix4;
|
|
13854
13326
|
exports.MeshHelper = MeshHelper;
|
|
13855
13327
|
exports.ModelPlugin = ModelPlugin;
|
|
13856
|
-
exports.ModelTreeItem = ModelTreeItem;
|
|
13857
|
-
exports.ModelTreePlugin = ModelTreePlugin;
|
|
13858
13328
|
exports.PAnimTexture = PAnimTexture;
|
|
13859
|
-
exports.PAnimTrack = PAnimTrack;
|
|
13860
|
-
exports.PAnimation = PAnimation;
|
|
13861
|
-
exports.PAnimationManager = PAnimationManager;
|
|
13862
13329
|
exports.PBRShaderGUID = PBRShaderGUID;
|
|
13863
13330
|
exports.PCamera = PCamera;
|
|
13864
13331
|
exports.PCameraManager = PCameraManager;
|