@galacean/effects-plugin-model 2.0.0-alpha.12 → 2.0.0-alpha.13

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/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.0.0-alpha.12
6
+ * Version: v2.0.0-alpha.13
7
7
  */
8
8
 
9
9
  'use strict';
@@ -794,6 +794,41 @@ var ctrlMap = {
794
794
  return new CTRL(binary[index], start, byteLength / CTRL.BYTES_PER_ELEMENT);
795
795
  }
796
796
 
797
+ function _array_like_to_array(arr, len) {
798
+ if (len == null || len > arr.length) len = arr.length;
799
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
800
+ return arr2;
801
+ }
802
+
803
+ function _unsupported_iterable_to_array(o, minLen) {
804
+ if (!o) return;
805
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
806
+ var n = Object.prototype.toString.call(o).slice(8, -1);
807
+ if (n === "Object" && o.constructor) n = o.constructor.name;
808
+ if (n === "Map" || n === "Set") return Array.from(n);
809
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
810
+ }
811
+
812
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
813
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
814
+ if (it) return (it = it.call(o)).next.bind(it);
815
+ // Fallback for engines without symbol support
816
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
817
+ if (it) o = it;
818
+ var i = 0;
819
+ return function() {
820
+ if (i >= o.length) return {
821
+ done: true
822
+ };
823
+ return {
824
+ done: false,
825
+ value: o[i++]
826
+ };
827
+ };
828
+ }
829
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
830
+ }
831
+
797
832
  var InterpolationSampler = /*#__PURE__*/ function() {
798
833
  function InterpolationSampler(time, data, componentCount) {
799
834
  this.time = time;
@@ -1090,7 +1125,7 @@ exports.TextureDataMode = void 0;
1090
1125
  */ _this.skeleton = 0;
1091
1126
  /**
1092
1127
  * 关节索引
1093
- */ _this.jointList = [];
1128
+ */ _this.jointItem = [];
1094
1129
  /**
1095
1130
  * 逆绑定矩阵
1096
1131
  */ _this.inverseBindMatrices = [];
@@ -1105,27 +1140,26 @@ exports.TextureDataMode = void 0;
1105
1140
  var _proto = PSkin.prototype;
1106
1141
  /**
1107
1142
  * 创建蒙皮对象
1108
- * @param options - 蒙皮相关数据
1143
+ * @param props - 蒙皮相关数据
1109
1144
  * @param engine - 引擎对象
1110
- * @param parentItem - 场景树父元素
1111
- */ _proto.create = function create(options, engine, parentItem) {
1112
- var _options_name;
1113
- this.name = this.genName((_options_name = options.name) != null ? _options_name : "Unnamed skin");
1145
+ * @param rootBoneItem - 场景树父元素
1146
+ */ _proto.create = function create(props, engine, rootBoneItem) {
1147
+ var _props_rootBoneName;
1148
+ this.name = (_props_rootBoneName = props.rootBoneName) != null ? _props_rootBoneName : "Unnamed skin";
1114
1149
  this.type = exports.PObjectType.skin;
1115
1150
  //
1116
- this.parentItem = parentItem;
1117
- var _options_skeleton;
1118
- this.skeleton = (_options_skeleton = options.skeleton) != null ? _options_skeleton : -1;
1119
- this.jointList = options.joints;
1151
+ this.rootBoneItem = rootBoneItem;
1152
+ this.skeleton = -1;
1153
+ this.jointItem = this.getJointItems(props, rootBoneItem);
1120
1154
  this.animationMatrices = [];
1121
1155
  //
1122
1156
  this.inverseBindMatrices = [];
1123
1157
  //
1124
1158
  this.textureDataMode = this.getTextureDataMode(this.getJointCount(), engine);
1125
- var matList = options.inverseBindMatrices;
1159
+ var matList = props.inverseBindMatrices;
1126
1160
  if (matList !== undefined && matList.length > 0) {
1127
- if (matList.length % 16 !== 0 || matList.length !== this.jointList.length * 16) {
1128
- throw new Error("Invalid array length, invert bind matrices " + matList.length + ", joint array " + this.jointList.length);
1161
+ if (matList.length % 16 !== 0 || matList.length !== this.jointItem.length * 16) {
1162
+ throw new Error("Invalid array length, invert bind matrices " + matList.length + ", joint array " + this.jointItem.length);
1129
1163
  }
1130
1164
  var matrixCount = matList.length / 16;
1131
1165
  for(var i = 0; i < matrixCount; i++){
@@ -1138,26 +1172,17 @@ exports.TextureDataMode = void 0;
1138
1172
  * 更新蒙皮矩阵
1139
1173
  */ _proto.updateSkinMatrices = function updateSkinMatrices() {
1140
1174
  var _this = this;
1141
- var _this_parentItem;
1142
1175
  this.animationMatrices = [];
1143
- var parentTree = (_this_parentItem = this.parentItem) == null ? void 0 : _this_parentItem.getComponent(exports.ModelTreeComponent);
1144
- if (parentTree !== undefined) {
1145
- for(var i = 0; i < this.jointList.length; i++){
1146
- var joint = this.jointList[i];
1147
- var node = parentTree.content.getNodeById(joint);
1148
- // let parent = node?.transform.parentTransform;
1149
- // while(parent !== undefined){
1150
- // const pos = parent.position;
1151
- // parent.setPosition(pos[0], pos[1], pos[2]);
1152
- // parent = parent.parentTransform;
1153
- // }
1154
- if (node === undefined) {
1155
- console.error("Can't find joint " + joint + " in node tree " + this.parentItem + ".");
1156
- break;
1157
- }
1158
- var mat4 = node.transform.getWorldMatrix();
1159
- this.animationMatrices.push(mat4.clone());
1160
- }
1176
+ for(var i = 0; i < this.jointItem.length; i++){
1177
+ var node = this.jointItem[i];
1178
+ // let parent = node?.transform.parentTransform;
1179
+ // while(parent !== undefined){
1180
+ // const pos = parent.position;
1181
+ // parent.setPosition(pos[0], pos[1], pos[2]);
1182
+ // parent = parent.parentTransform;
1183
+ // }
1184
+ var mat4 = node.transform.getWorldMatrix();
1185
+ this.animationMatrices.push(mat4.clone());
1161
1186
  }
1162
1187
  if (this.animationMatrices.length === this.inverseBindMatrices.length) {
1163
1188
  this.animationMatrices.forEach(function(mat, index) {
@@ -1192,13 +1217,13 @@ exports.TextureDataMode = void 0;
1192
1217
  * 更新父元素
1193
1218
  * @param parentItem - 场景树父元素
1194
1219
  */ _proto.updateParentItem = function updateParentItem(parentItem) {
1195
- this.parentItem = parentItem;
1220
+ this.rootBoneItem = parentItem;
1196
1221
  };
1197
1222
  /**
1198
1223
  * 获取关节点数
1199
1224
  * @returns
1200
1225
  */ _proto.getJointCount = function getJointCount() {
1201
- return this.jointList.length;
1226
+ return this.jointItem.length;
1202
1227
  };
1203
1228
  /**
1204
1229
  * 是否纹理数据模式
@@ -1209,8 +1234,8 @@ exports.TextureDataMode = void 0;
1209
1234
  /**
1210
1235
  * 销毁
1211
1236
  */ _proto.dispose = function dispose() {
1212
- this.parentItem = undefined;
1213
- this.jointList = [];
1237
+ this.rootBoneItem = undefined;
1238
+ this.jointItem = [];
1214
1239
  this.inverseBindMatrices = [];
1215
1240
  this.animationMatrices = [];
1216
1241
  };
@@ -1232,6 +1257,38 @@ exports.TextureDataMode = void 0;
1232
1257
  return 0;
1233
1258
  }
1234
1259
  };
1260
+ _proto.getJointItems = function getJointItems(props, rootBoneItem) {
1261
+ var _props_boneNames;
1262
+ var name2Item = this.genNodeName(rootBoneItem);
1263
+ var jointItems = [];
1264
+ (_props_boneNames = props.boneNames) == null ? void 0 : _props_boneNames.forEach(function(boneName) {
1265
+ var node = name2Item[boneName];
1266
+ if (!node) {
1267
+ throw new Error("Can't find node of bone name " + boneName);
1268
+ }
1269
+ jointItems.push(node);
1270
+ });
1271
+ return jointItems;
1272
+ };
1273
+ _proto.genNodeName = function genNodeName(node) {
1274
+ var name2Item = {};
1275
+ var nameList = [];
1276
+ name2Item[""] = node;
1277
+ for(var _iterator = _create_for_of_iterator_helper_loose(node.children), _step; !(_step = _iterator()).done;){
1278
+ var child = _step.value;
1279
+ this.genNodeNameDFS(child, nameList, name2Item);
1280
+ }
1281
+ return name2Item;
1282
+ };
1283
+ _proto.genNodeNameDFS = function genNodeNameDFS(node, nameList, name2Item) {
1284
+ nameList.push(node.name);
1285
+ name2Item[nameList.join("/")] = node;
1286
+ for(var _iterator = _create_for_of_iterator_helper_loose(node.children), _step; !(_step = _iterator()).done;){
1287
+ var child = _step.value;
1288
+ this.genNodeNameDFS(child, nameList, name2Item);
1289
+ }
1290
+ nameList.pop();
1291
+ };
1235
1292
  return PSkin;
1236
1293
  }(PObject);
1237
1294
  /**
@@ -1249,6 +1306,10 @@ exports.TextureDataMode = void 0;
1249
1306
  * 范围要在 `[0, 8]` 之间,否则会报错。
1250
1307
  */ _this.morphWeightsLength = 0;
1251
1308
  /**
1309
+ * weights 数组的具体数据,来自动画控制器的每帧更新
1310
+ * 数组的长度必须和 morphWeightsLength 相同,否则会出错。
1311
+ */ _this.morphWeightsArray = [];
1312
+ /**
1252
1313
  * 是否有 Position 相关的 Morph 动画,shader 中需要知道
1253
1314
  */ _this.hasPositionMorph = false;
1254
1315
  /**
@@ -1290,7 +1351,7 @@ exports.TextureDataMode = void 0;
1290
1351
  });
1291
1352
  if (this.morphWeightsLength > 0) {
1292
1353
  // 有Morph动画,申请weights数据,判断各个属性是否有相关动画
1293
- this.morphWeightsArray = new Float32Array(this.morphWeightsLength);
1354
+ this.morphWeightsArray = Array(this.morphWeightsLength).fill(0);
1294
1355
  this.hasPositionMorph = positionCount == this.morphWeightsLength;
1295
1356
  this.hasNormalMorph = normalCount == this.morphWeightsLength;
1296
1357
  this.hasTangentMorph = tangentCount == this.morphWeightsLength;
@@ -1317,14 +1378,11 @@ exports.TextureDataMode = void 0;
1317
1378
  }
1318
1379
  return true;
1319
1380
  };
1320
- _proto.dispose = function dispose() {
1321
- this.morphWeightsArray = undefined;
1322
- };
1323
1381
  /**
1324
1382
  * 初始化 Morph target 的权重数组
1325
1383
  * @param weights - glTF Mesh 的权重数组,长度必须严格一致
1326
1384
  */ _proto.initWeights = function initWeights(weights) {
1327
- if (this.morphWeightsArray === undefined) {
1385
+ if (this.morphWeightsArray.length === 0) {
1328
1386
  return;
1329
1387
  }
1330
1388
  var morphWeights = this.morphWeightsArray;
@@ -1334,6 +1392,16 @@ exports.TextureDataMode = void 0;
1334
1392
  }
1335
1393
  });
1336
1394
  };
1395
+ _proto.updateWeights = function updateWeights(weights) {
1396
+ var _this = this;
1397
+ if (weights.length != this.morphWeightsArray.length) {
1398
+ console.error("Length of morph weights mismatch: input " + weights.length + ", internel " + this.morphWeightsArray.length);
1399
+ return;
1400
+ }
1401
+ weights.forEach(function(value, index) {
1402
+ return _this.morphWeightsArray[index] = value;
1403
+ });
1404
+ };
1337
1405
  /**
1338
1406
  * 当前状态是否有 Morph 动画:
1339
1407
  * 需要判断 weights 数组长度,以及 Position、Normal 和 Tangent 是否有动画
@@ -2461,6 +2529,7 @@ function _assert_this_initialized(self) {
2461
2529
  _this.parentIndex = proxy.getParentIndex();
2462
2530
  _this.parentItem = proxy.parentItem;
2463
2531
  _this.parentItemId = parentId;
2532
+ _this.rootBoneItem = meshData.rootBone;
2464
2533
  _this.skin = proxy.getSkinObj(engine);
2465
2534
  _this.morph = proxy.getMorphObj();
2466
2535
  _this.hide = proxy.isHide();
@@ -2503,6 +2572,9 @@ function _assert_this_initialized(self) {
2503
2572
  */ _proto.update = function update() {
2504
2573
  if (this.owner !== undefined) {
2505
2574
  this.transform.fromEffectsTransform(this.owner.transform);
2575
+ if (this.morph && this.morph.hasMorph() && this.owner.morphWeights.length > 0) {
2576
+ this.morph.updateWeights(this.owner.morphWeights);
2577
+ }
2506
2578
  }
2507
2579
  };
2508
2580
  /**
@@ -3134,12 +3206,8 @@ function _assert_this_initialized(self) {
3134
3206
  // Morph 相关的数据更新,仅需要更新 weights 数组
3135
3207
  var morph = this.morph;
3136
3208
  if (morph !== undefined && morph.hasMorph()) {
3137
- var morphWeights = morph.morphWeightsArray;
3138
- var morphWeightNumbers = [];
3139
- morphWeights.forEach(function(val) {
3140
- return morphWeightNumbers.push(val);
3141
- });
3142
- material.setFloats("_morphWeights", morphWeightNumbers);
3209
+ var morphWeights = morph.morphWeightsArray.slice();
3210
+ material.setFloats("_morphWeights", morphWeights);
3143
3211
  }
3144
3212
  };
3145
3213
  _proto.updateUniformsByScene = function updateUniformsByScene(sceneStates) {
@@ -3390,7 +3458,18 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
3390
3458
  this.itemData = itemData;
3391
3459
  this.parentItem = parentItem;
3392
3460
  this.data = itemData;
3393
- this.morphObj = new PMorph();
3461
+ this.geometry = itemData.geometry;
3462
+ this.rootBoneItem = itemData.rootBone;
3463
+ var morphObj = new PMorph();
3464
+ if (morphObj.create(this.geometry)) {
3465
+ var _itemData_morph;
3466
+ // 设置初始权重数组
3467
+ if ((_itemData_morph = itemData.morph) == null ? void 0 : _itemData_morph.weights) {
3468
+ var _itemData_morph1;
3469
+ morphObj.initWeights((_itemData_morph1 = itemData.morph) == null ? void 0 : _itemData_morph1.weights);
3470
+ }
3471
+ this.morphObj = morphObj;
3472
+ }
3394
3473
  }
3395
3474
  var _proto = EffectsMeshProxy.prototype;
3396
3475
  _proto.hasMorphTarget = function hasMorphTarget() {
@@ -3432,20 +3511,17 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
3432
3511
  return this.data.materials.length;
3433
3512
  };
3434
3513
  _proto.hasSkin = function hasSkin() {
3435
- // FIXME: skin
3436
- //return this.options.skin !== undefined;
3437
- return false;
3514
+ var skin = this.geometry.getSkinProps();
3515
+ return !!(skin.rootBoneName && skin.boneNames && skin.inverseBindMatrices && this.rootBoneItem);
3438
3516
  };
3439
3517
  _proto.getSkinOpts = function getSkinOpts() {
3440
- // FIXME: skin
3441
- //return this.options.skin;
3442
- return;
3518
+ return this.geometry.getSkinProps();
3443
3519
  };
3444
3520
  _proto.getSkinObj = function getSkinObj(engine) {
3445
3521
  var skin = this.getSkinOpts();
3446
- if (skin !== undefined) {
3522
+ if (skin.rootBoneName && skin.boneNames && skin.inverseBindMatrices && this.rootBoneItem) {
3447
3523
  var skinObj = new PSkin();
3448
- skinObj.create(skin, engine, this.parentItem);
3524
+ skinObj.create(skin, engine, this.rootBoneItem);
3449
3525
  return skinObj;
3450
3526
  }
3451
3527
  return undefined;
@@ -3843,7 +3919,7 @@ var shadowPassFrag = "#define FEATURES\n#include <shadowCommon.vert.glsl>\n#incl
3843
3919
 
3844
3920
  var skyboxVert = "precision highp float;\n#define FEATURES\n#include <webglCompatibility.glsl>\nvsIn vec3 aPos;vsOut vec3 v_CameraDir;uniform mat4 _InvViewProjectionMatrix;void main(){vec4 dir=_InvViewProjectionMatrix*vec4(aPos.xy,1,1);v_CameraDir=normalize(dir.xyz/dir.w);gl_Position=vec4(aPos.xy,0.99999,1);}";
3845
3921
 
3846
- var skyboxFrag = "precision highp float;\n#define FEATURES\n#if !defined(WEBGL2) && defined(USE_TEX_LOD)\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#if !defined(WEBGL2)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#include <webglCompatibility.glsl>\n#include <extensions.frag.glsl>\n#ifdef WEBGL2\nout vec4 outFragColor;\n#else\n#define outFragColor gl_FragColor\n#endif\nuniform sampler2D _brdfLUT;uniform vec2 _IblIntensity;uniform int _MipCount;uniform samplerCube _DiffuseEnvSampler;uniform samplerCube _SpecularEnvSampler;fsIn vec3 v_CameraDir;\n#ifdef IRRADIANCE_COEFFICIENTS\nstruct SHCoefficients{vec3 l00,l1m1,l10,l11,l2m2,l2m1,l20,l21,l22;};uniform SHCoefficients _shCoefficients;vec3 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\nvec3 getIBLContribution(vec3 n,vec3 v){const float metallic=0.9;const float perceptualRoughness=0.1;const vec4 baseColor=vec4(1.0);const vec3 f0=vec3(0.04);const vec3 diffuseColor=baseColor.rgb*(vec3(1.0)-f0)*(1.0-metallic);const vec3 specularColor=mix(f0,baseColor.rgb,metallic);float NdotV=clamp(dot(n,v),0.0,1.0);float lod=clamp(perceptualRoughness*float(_MipCount),0.0,float(_MipCount));vec3 reflection=normalize(reflect(-v,n));vec2 brdfSamplePoint=clamp(vec2(NdotV,perceptualRoughness),vec2(0.0,0.0),vec2(1.0,1.0));vec2 brdf=texture2D(_brdfLUT,brdfSamplePoint).rg;vec4 diffuseSample=vec4(1.0,0.0,0.0,1.0);\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 irradiance=getIrradiance(n,_shCoefficients);diffuseSample=vec4(irradiance,1.0);\n#else\ndiffuseSample=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\nvec3 diffuseLight=diffuseSample.rgb;vec3 specularLight=specularSample.rgb;vec3 diffuse=diffuseLight*diffuseColor;vec3 specular=specularLight*(specularColor*brdf.x+brdf.y);return diffuse*_IblIntensity[0]+specular*_IblIntensity[1];}void main(){vec3 dir=normalize(v_CameraDir);outFragColor=vec4(getIBLContribution(dir,dir),1.0);}";
3922
+ var skyboxFrag = "\n#define FEATURES\n#if !defined(WEBGL2) && defined(USE_TEX_LOD)\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#if !defined(WEBGL2)\n#extension GL_OES_standard_derivatives : enable\n#endif\nprecision highp float;\n#include <webglCompatibility.glsl>\n#include <extensions.frag.glsl>\n#ifdef WEBGL2\nout vec4 outFragColor;\n#else\n#define outFragColor gl_FragColor\n#endif\nuniform sampler2D _brdfLUT;uniform vec2 _IblIntensity;uniform int _MipCount;uniform samplerCube _DiffuseEnvSampler;uniform samplerCube _SpecularEnvSampler;fsIn vec3 v_CameraDir;\n#ifdef IRRADIANCE_COEFFICIENTS\nstruct SHCoefficients{vec3 l00,l1m1,l10,l11,l2m2,l2m1,l20,l21,l22;};uniform SHCoefficients _shCoefficients;vec3 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\nvec3 getIBLContribution(vec3 n,vec3 v){const float metallic=0.9;const float perceptualRoughness=0.1;const vec4 baseColor=vec4(1.0);const vec3 f0=vec3(0.04);const vec3 diffuseColor=baseColor.rgb*(vec3(1.0)-f0)*(1.0-metallic);const vec3 specularColor=mix(f0,baseColor.rgb,metallic);float NdotV=clamp(dot(n,v),0.0,1.0);float lod=clamp(perceptualRoughness*float(_MipCount),0.0,float(_MipCount));vec3 reflection=normalize(reflect(-v,n));vec2 brdfSamplePoint=clamp(vec2(NdotV,perceptualRoughness),vec2(0.0,0.0),vec2(1.0,1.0));vec2 brdf=texture2D(_brdfLUT,brdfSamplePoint).rg;vec4 diffuseSample=vec4(1.0,0.0,0.0,1.0);\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 irradiance=getIrradiance(n,_shCoefficients);diffuseSample=vec4(irradiance,1.0);\n#else\ndiffuseSample=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\nvec3 diffuseLight=diffuseSample.rgb;vec3 specularLight=specularSample.rgb;vec3 diffuse=diffuseLight*diffuseColor;vec3 specular=specularLight*(specularColor*brdf.x+brdf.y);return diffuse*_IblIntensity[0]+specular*_IblIntensity[1];}void main(){vec3 dir=normalize(v_CameraDir);outFragColor=vec4(getIBLContribution(dir,dir),1.0);}";
3847
3923
 
3848
3924
  var animationVertGLSL = "#ifdef HAS_TARGET_POSITION0\nvsIn vec3 aTargetPosition0;\n#endif\n#ifdef HAS_TARGET_POSITION1\nvsIn vec3 aTargetPosition1;\n#endif\n#ifdef HAS_TARGET_POSITION2\nvsIn vec3 aTargetPosition2;\n#endif\n#ifdef HAS_TARGET_POSITION3\nvsIn vec3 aTargetPosition3;\n#endif\n#ifdef HAS_TARGET_POSITION4\nvsIn vec3 aTargetPosition4;\n#endif\n#ifdef HAS_TARGET_POSITION5\nvsIn vec3 aTargetPosition5;\n#endif\n#ifdef HAS_TARGET_POSITION6\nvsIn vec3 aTargetPosition6;\n#endif\n#ifdef HAS_TARGET_POSITION7\nvsIn vec3 aTargetPosition7;\n#endif\n#ifdef HAS_TARGET_NORMAL0\nvsIn vec3 aTargetNormal0;\n#endif\n#ifdef HAS_TARGET_NORMAL1\nvsIn vec3 aTargetNormal1;\n#endif\n#ifdef HAS_TARGET_NORMAL2\nvsIn vec3 aTargetNormal2;\n#endif\n#ifdef HAS_TARGET_NORMAL3\nvsIn vec3 aTargetNormal3;\n#endif\n#ifdef HAS_TARGET_NORMAL4\nvsIn vec3 aTargetNormal4;\n#endif\n#ifdef HAS_TARGET_TANGENT0\nvsIn vec3 aTargetTangent0;\n#endif\n#ifdef HAS_TARGET_TANGENT1\nvsIn vec3 aTargetTangent1;\n#endif\n#ifdef HAS_TARGET_TANGENT2\nvsIn vec3 aTargetTangent2;\n#endif\n#ifdef HAS_TARGET_TANGENT3\nvsIn vec3 aTargetTangent3;\n#endif\n#ifdef HAS_TARGET_TANGENT4\nvsIn vec3 aTargetTangent4;\n#endif\n#ifdef USE_MORPHING\nuniform float _morphWeights[WEIGHT_COUNT];\n#endif\n#ifdef HAS_JOINT_SET1\nvsIn vec4 aJoints;\n#endif\n#ifdef HAS_JOINT_SET2\nvsIn vec4 aJoint2;\n#endif\n#ifdef HAS_WEIGHT_SET1\nvsIn vec4 aWeights;\n#endif\n#ifdef HAS_WEIGHT_SET2\nvsIn vec4 aWeight2;\n#endif\n#ifdef USE_SKINNING\n#ifdef USE_SKINNING_TEXTURE\nuniform sampler2D _jointMatrixSampler;uniform sampler2D _jointNormalMatrixSampler;\n#else\nuniform mat4 _jointMatrix[JOINT_COUNT];uniform mat4 _jointNormalMatrix[JOINT_COUNT];\n#endif\n#endif\n#define ROW0_U ((0.5 + 0.0) / 4.0)\n#define ROW1_U ((0.5 + 1.0) / 4.0)\n#define ROW2_U ((0.5 + 2.0) / 4.0)\n#define ROW3_U ((0.5 + 3.0) / 4.0)\n#ifdef USE_SKINNING\nmat4 getJointMatrix(float boneNdx){\n#ifdef USE_SKINNING_TEXTURE\nfloat v=(boneNdx+0.5)/float(JOINT_COUNT);return mat4(texture2D(_jointMatrixSampler,vec2(ROW0_U,v)),texture2D(_jointMatrixSampler,vec2(ROW1_U,v)),texture2D(_jointMatrixSampler,vec2(ROW2_U,v)),texture2D(_jointMatrixSampler,vec2(ROW3_U,v)));\n#else\nreturn _jointMatrix[int(boneNdx)];\n#endif\n}mat4 getJointNormalMatrix(float boneNdx){\n#ifdef USE_SKINNING_TEXTURE\nfloat v=(boneNdx+0.5)/float(JOINT_COUNT);return mat4(texture2D(_jointNormalMatrixSampler,vec2(ROW0_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW1_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW2_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW3_U,v)));\n#else\nreturn _jointNormalMatrix[int(boneNdx)];\n#endif\n}mat4 getSkinningMatrix(){mat4 skin=mat4(0);\n#if defined(HAS_WEIGHT_SET1) && defined(HAS_JOINT_SET1)\nskin+=aWeights.x*getJointMatrix(aJoints.x)+aWeights.y*getJointMatrix(aJoints.y)+aWeights.z*getJointMatrix(aJoints.z)+aWeights.w*getJointMatrix(aJoints.w);\n#endif\nreturn skin;}mat4 getSkinningNormalMatrix(){mat4 skin=mat4(0);\n#if defined(HAS_WEIGHT_SET1) && defined(HAS_JOINT_SET1)\nskin+=aWeights.x*getJointNormalMatrix(aJoints.x)+aWeights.y*getJointNormalMatrix(aJoints.y)+aWeights.z*getJointNormalMatrix(aJoints.z)+aWeights.w*getJointNormalMatrix(aJoints.w);\n#endif\nreturn skin;}\n#endif\n#ifdef USE_MORPHING\nvec4 getTargetPosition(){vec4 pos=vec4(0);\n#ifdef HAS_TARGET_POSITION0\npos.xyz+=_morphWeights[0]*aTargetPosition0;\n#endif\n#ifdef HAS_TARGET_POSITION1\npos.xyz+=_morphWeights[1]*aTargetPosition1;\n#endif\n#ifdef HAS_TARGET_POSITION2\npos.xyz+=_morphWeights[2]*aTargetPosition2;\n#endif\n#ifdef HAS_TARGET_POSITION3\npos.xyz+=_morphWeights[3]*aTargetPosition3;\n#endif\n#ifdef HAS_TARGET_POSITION4\npos.xyz+=_morphWeights[4]*aTargetPosition4;\n#endif\nreturn pos;}vec4 getTargetNormal(){vec4 normal=vec4(0);\n#ifdef HAS_TARGET_NORMAL0\nnormal.xyz+=_morphWeights[0]*aTargetNormal0;\n#endif\n#ifdef HAS_TARGET_NORMAL1\nnormal.xyz+=_morphWeights[1]*aTargetNormal1;\n#endif\n#ifdef HAS_TARGET_NORMAL2\nnormal.xyz+=_morphWeights[2]*aTargetNormal2;\n#endif\n#ifdef HAS_TARGET_NORMAL3\nnormal.xyz+=_morphWeights[3]*aTargetNormal3;\n#endif\n#ifdef HAS_TARGET_NORMAL4\nnormal.xyz+=_morphWeights[4]*aTargetNormal4;\n#endif\nreturn normal;}vec4 getTargetTangent(){vec4 tangent=vec4(0);\n#ifdef HAS_TARGET_TANGENT0\ntangent.xyz+=_morphWeights[0]*aTargetTangent0;\n#endif\n#ifdef HAS_TARGET_TANGENT1\ntangent.xyz+=_morphWeights[1]*aTargetTangent1;\n#endif\n#ifdef HAS_TARGET_TANGENT2\ntangent.xyz+=_morphWeights[2]*aTargetTangent2;\n#endif\n#ifdef HAS_TARGET_TANGENT3\ntangent.xyz+=_morphWeights[3]*aTargetTangent3;\n#endif\n#ifdef HAS_TARGET_TANGENT4\ntangent.xyz+=_morphWeights[4]*aTargetTangent4;\n#endif\nreturn tangent;}\n#endif\n";
3849
3925
 
@@ -4298,6 +4374,9 @@ exports.ModelMeshComponent = /*#__PURE__*/ function(RendererComponent) {
4298
4374
  var _this;
4299
4375
  _this = RendererComponent.call(this, engine) || this;
4300
4376
  /**
4377
+ * morph 动画权重
4378
+ */ _this.morphWeights = [];
4379
+ /**
4301
4380
  * 获取点击测试参数,根据元素包围盒进行相交测试,Mesh 对象会进行更加精确的点击测试
4302
4381
  * @param force - 是否强制进行点击测试
4303
4382
  * @returns 点击测试参数
@@ -4614,7 +4693,6 @@ exports.ModelCameraComponent = /*#__PURE__*/ function(ItemBehaviour) {
4614
4693
  */ _proto.start = function start() {
4615
4694
  this.createContent();
4616
4695
  this.item.type = VFX_ITEM_TYPE_3D;
4617
- this.timeline = this.item.getComponent(effects.TimelineComponent);
4618
4696
  var scene = getSceneManager(this);
4619
4697
  scene == null ? void 0 : scene.addItem(this.content);
4620
4698
  this.updateMainCamera();
@@ -4666,19 +4744,11 @@ exports.ModelCameraComponent = /*#__PURE__*/ function(ItemBehaviour) {
4666
4744
  * @param position - 位置
4667
4745
  * @param rotation - 旋转
4668
4746
  */ _proto.setTransform = function setTransform(position, rotation) {
4669
- var _this_timeline_findTrack, _this_timeline;
4670
- var clip = (_this_timeline = this.timeline) == null ? void 0 : (_this_timeline_findTrack = _this_timeline.findTrack("AnimationTrack")) == null ? void 0 : _this_timeline_findTrack.findClip("AnimationTimelineClip");
4671
- if (position !== undefined) {
4747
+ if (position) {
4672
4748
  this.transform.setPosition(position.x, position.y, position.z);
4673
- if (clip) {
4674
- clip.playable.originalTransform.position = position.clone();
4675
- }
4676
4749
  }
4677
- if (rotation !== undefined) {
4750
+ if (rotation) {
4678
4751
  this.transform.setRotation(rotation.x, rotation.y, rotation.z);
4679
- if (clip) {
4680
- clip.playable.originalTransform.rotation = rotation.clone();
4681
- }
4682
4752
  }
4683
4753
  this.updateMainCamera();
4684
4754
  };
@@ -4687,6 +4757,155 @@ exports.ModelCameraComponent = /*#__PURE__*/ function(ItemBehaviour) {
4687
4757
  exports.ModelCameraComponent = __decorate([
4688
4758
  effects.effectsClass(effects.spec.DataType.CameraComponent)
4689
4759
  ], exports.ModelCameraComponent);
4760
+ exports.AnimationComponent = /*#__PURE__*/ function(ItemBehaviour) {
4761
+ _inherits(AnimationComponent, ItemBehaviour);
4762
+ function AnimationComponent(engine) {
4763
+ var _this;
4764
+ _this = ItemBehaviour.call(this, engine) || this;
4765
+ _this.elapsedTime = 0;
4766
+ _this.animation = -1;
4767
+ _this.clips = [];
4768
+ return _this;
4769
+ }
4770
+ var _proto = AnimationComponent.prototype;
4771
+ /**
4772
+ * 组件开始,需要创建内部对象和添加到场景管理器中
4773
+ */ _proto.start = function start() {
4774
+ this.elapsedTime = 0;
4775
+ this.item.type = VFX_ITEM_TYPE_3D;
4776
+ };
4777
+ /**
4778
+ * 组件更新,更新内部对象状态
4779
+ * @param dt - 更新间隔
4780
+ */ _proto.update = function update(dt) {
4781
+ this.elapsedTime += dt * 0.001;
4782
+ if (this.animation >= 0 && this.animation < this.clips.length) {
4783
+ this.clips[this.animation].sampleAnimation(this.item, this.elapsedTime);
4784
+ }
4785
+ };
4786
+ /**
4787
+ * 组件销毁
4788
+ */ _proto.onDestroy = function onDestroy() {};
4789
+ /**
4790
+ * 反序列化,记录传入参数
4791
+ * @param data - 组件参数
4792
+ */ _proto.fromData = function fromData(data) {
4793
+ var _this = this;
4794
+ ItemBehaviour.prototype.fromData.call(this, data);
4795
+ this.data = data;
4796
+ var _data_name;
4797
+ //
4798
+ this.name = (_data_name = data.name) != null ? _data_name : "<empty>";
4799
+ var _data_animation;
4800
+ this.animation = (_data_animation = data.animation) != null ? _data_animation : -1;
4801
+ this.clips = [];
4802
+ data.animationClips.forEach(function(clipData) {
4803
+ var clipObj = new ModelAnimationClip(_this.engine);
4804
+ clipObj.setFromAnimationClip(clipData);
4805
+ _this.clips.push(clipObj);
4806
+ });
4807
+ };
4808
+ return AnimationComponent;
4809
+ }(effects.ItemBehaviour);
4810
+ exports.AnimationComponent = __decorate([
4811
+ effects.effectsClass(effects.spec.DataType.AnimationComponent)
4812
+ ], exports.AnimationComponent);
4813
+ var ModelAnimationClip = /*#__PURE__*/ function(AnimationClip) {
4814
+ _inherits(ModelAnimationClip, AnimationClip);
4815
+ function ModelAnimationClip() {
4816
+ var _this;
4817
+ _this = AnimationClip.apply(this, arguments) || this;
4818
+ _this.path2Node = {};
4819
+ return _this;
4820
+ }
4821
+ var _proto = ModelAnimationClip.prototype;
4822
+ _proto.sampleAnimation = function sampleAnimation(vfxItem, time) {
4823
+ var duration = vfxItem.duration;
4824
+ var life = Math.max(0, time) % duration;
4825
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.positionCurves), _step; !(_step = _iterator()).done;){
4826
+ var curve = _step.value;
4827
+ var maxTime = curve.keyFrames.getMaxTime();
4828
+ var value = curve.keyFrames.getValue(life % maxTime);
4829
+ var target = this.getTargetItem(vfxItem, curve.path);
4830
+ target == null ? void 0 : target.transform.setPosition(value.x, value.y, value.z);
4831
+ }
4832
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(this.rotationCurves), _step1; !(_step1 = _iterator1()).done;){
4833
+ var curve1 = _step1.value;
4834
+ var maxTime1 = curve1.keyFrames.getMaxTime();
4835
+ var value1 = curve1.keyFrames.getValue(life % maxTime1);
4836
+ var target1 = this.getTargetItem(vfxItem, curve1.path);
4837
+ target1 == null ? void 0 : target1.transform.setQuaternion(value1.x, value1.y, value1.z, value1.w);
4838
+ }
4839
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(this.scaleCurves), _step2; !(_step2 = _iterator2()).done;){
4840
+ var curve2 = _step2.value;
4841
+ var maxTime2 = curve2.keyFrames.getMaxTime();
4842
+ var value2 = curve2.keyFrames.getValue(life % maxTime2);
4843
+ var target2 = this.getTargetItem(vfxItem, curve2.path);
4844
+ target2 == null ? void 0 : target2.transform.setScale(value2.x, value2.y, value2.z);
4845
+ }
4846
+ for(var _iterator3 = _create_for_of_iterator_helper_loose(this.floatCurves), _step3; !(_step3 = _iterator3()).done;){
4847
+ var curve3 = _step3.value;
4848
+ var maxTime3 = curve3.keyFrames.getMaxTime();
4849
+ var value3 = curve3.keyFrames.getValue(life % maxTime3);
4850
+ var target3 = this.getTargetItem(vfxItem, curve3.path);
4851
+ if (curve3.className === "ModelMeshComponent") {
4852
+ var component = target3 == null ? void 0 : target3.getComponent(exports.ModelMeshComponent);
4853
+ if (component) {
4854
+ var properties = curve3.property.split(".");
4855
+ setProperty(component, properties, value3);
4856
+ } else {
4857
+ console.error("Can't find mesh component");
4858
+ }
4859
+ } else {
4860
+ console.warn("Ignore curve: className " + curve3.className);
4861
+ }
4862
+ }
4863
+ };
4864
+ _proto.setFromAnimationClip = function setFromAnimationClip(clip) {
4865
+ this.positionCurves = clip.positionCurves.slice();
4866
+ this.rotationCurves = clip.rotationCurves.slice();
4867
+ this.scaleCurves = clip.scaleCurves.slice();
4868
+ this.floatCurves = clip.floatCurves.slice();
4869
+ };
4870
+ _proto.getTargetItem = function getTargetItem(rootItem, path) {
4871
+ if (this.path2Node[path]) {
4872
+ return this.path2Node[path];
4873
+ }
4874
+ var target = rootItem;
4875
+ var nameList = path.split("/");
4876
+ for(var _iterator = _create_for_of_iterator_helper_loose(nameList), _step; !(_step = _iterator()).done;){
4877
+ var name = _step.value;
4878
+ var findTag = false;
4879
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(target.children), _step1; !(_step1 = _iterator1()).done;){
4880
+ var child = _step1.value;
4881
+ if (child.name === name) {
4882
+ target = child;
4883
+ findTag = true;
4884
+ break;
4885
+ }
4886
+ }
4887
+ if (!findTag) {
4888
+ throw new Error("Can't find path in tree " + rootItem.id + ", " + path);
4889
+ }
4890
+ }
4891
+ this.path2Node[path] = target;
4892
+ return target;
4893
+ };
4894
+ return ModelAnimationClip;
4895
+ }(effects.AnimationClip);
4896
+ function setProperty(obj, properties, value) {
4897
+ var len = properties.length;
4898
+ var current = obj;
4899
+ for(var i = 0; i < len - 1; i++){
4900
+ var propName = properties[i];
4901
+ if (!(propName in current) || typeof current[propName] !== "object") {
4902
+ console.error("Invalid properties " + properties);
4903
+ return;
4904
+ }
4905
+ current = current[propName];
4906
+ }
4907
+ current[properties[len - 1]] = value;
4908
+ }
4690
4909
 
4691
4910
  // 射线与带旋转的包围盒求交
4692
4911
  // function transformDirection (m: Matrix4, direction: Vector3) {
@@ -11789,44 +12008,9 @@ var GLTFHelper = /*#__PURE__*/ function() {
11789
12008
  return GLTFHelper;
11790
12009
  }();
11791
12010
 
11792
- function _array_like_to_array(arr, len) {
11793
- if (len == null || len > arr.length) len = arr.length;
11794
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
11795
- return arr2;
11796
- }
11797
-
11798
- function _unsupported_iterable_to_array(o, minLen) {
11799
- if (!o) return;
11800
- if (typeof o === "string") return _array_like_to_array(o, minLen);
11801
- var n = Object.prototype.toString.call(o).slice(8, -1);
11802
- if (n === "Object" && o.constructor) n = o.constructor.name;
11803
- if (n === "Map" || n === "Set") return Array.from(n);
11804
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
11805
- }
11806
-
11807
- function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
11808
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
11809
- if (it) return (it = it.call(o)).next.bind(it);
11810
- // Fallback for engines without symbol support
11811
- if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
11812
- if (it) o = it;
11813
- var i = 0;
11814
- return function() {
11815
- if (i >= o.length) return {
11816
- done: true
11817
- };
11818
- return {
11819
- done: false,
11820
- value: o[i++]
11821
- };
11822
- };
11823
- }
11824
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
11825
- }
11826
-
11827
12011
  var JSONConverter = /*#__PURE__*/ function() {
11828
12012
  function JSONConverter(player) {
11829
- this.treeItemList = [];
12013
+ this.treeInfo = new TreeInfo();
11830
12014
  this.engine = player.renderer.engine;
11831
12015
  this.renderer = player.renderer;
11832
12016
  this.downloader = new effects.Downloader();
@@ -11895,7 +12079,7 @@ var JSONConverter = /*#__PURE__*/ function() {
11895
12079
  case 7:
11896
12080
  // @ts-expect-error
11897
12081
  oldScene.bins = binFiles;
11898
- newScene = {
12082
+ newScene = _extends({}, oldScene, {
11899
12083
  version: "3.0",
11900
12084
  playerVersion: {
11901
12085
  web: "3.0",
@@ -11903,18 +12087,14 @@ var JSONConverter = /*#__PURE__*/ function() {
11903
12087
  },
11904
12088
  type: "ge",
11905
12089
  compositions: [],
11906
- compositionId: oldScene.compositionId,
11907
12090
  images: [],
11908
- shapes: oldScene.shapes,
11909
- plugins: oldScene.plugins,
11910
12091
  textures: [],
11911
12092
  items: [],
11912
12093
  components: [],
11913
12094
  materials: [],
11914
12095
  shaders: [],
11915
12096
  geometries: []
11916
- };
11917
- _this.treeItemList = [];
12097
+ });
11918
12098
  _this.setImage(newScene, oldScene);
11919
12099
  return [
11920
12100
  4,
@@ -12045,8 +12225,6 @@ var JSONConverter = /*#__PURE__*/ function() {
12045
12225
  var comp = _step.value;
12046
12226
  if (comp.dataType === effects.spec.DataType.SkyboxComponent) {
12047
12227
  newComponents.push(this.createSkyboxComponent(comp, newScene));
12048
- } else if (comp.dataType === effects.spec.DataType.MeshComponent) {
12049
- newComponents.push(this.createMeshComponent(comp, newScene, oldScene));
12050
12228
  } else if (comp.dataType === effects.spec.DataType.LightComponent) {
12051
12229
  newComponents.push(this.createLightComponent(comp, newScene));
12052
12230
  } else if (comp.dataType === effects.spec.DataType.CameraComponent) {
@@ -12058,16 +12236,22 @@ var JSONConverter = /*#__PURE__*/ function() {
12058
12236
  treeComp.options.tree.animation = undefined;
12059
12237
  treeComp.options.tree.animations = undefined;
12060
12238
  newComponents.push(comp);
12061
- } else {
12239
+ } else if (comp.dataType !== effects.spec.DataType.MeshComponent) {
12062
12240
  newComponents.push(comp);
12063
12241
  }
12064
12242
  }
12243
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(oldScene.components), _step1; !(_step1 = _iterator1()).done;){
12244
+ var comp1 = _step1.value;
12245
+ if (comp1.dataType === effects.spec.DataType.MeshComponent) {
12246
+ newComponents.push(this.createMeshComponent(comp1, newScene, oldScene));
12247
+ }
12248
+ }
12065
12249
  };
12066
12250
  _proto.setItem = function setItem(newScene, oldScene) {};
12067
12251
  _proto.setComposition = function setComposition(newScene, oldScene) {
12068
12252
  var _newScene_items;
12069
12253
  newScene.items = oldScene.items;
12070
- (_newScene_items = newScene.items).push.apply(_newScene_items, [].concat(this.treeItemList));
12254
+ (_newScene_items = newScene.items).push.apply(_newScene_items, [].concat(this.treeInfo.getAllTreeNodeList()));
12071
12255
  newScene.compositionId = oldScene.compositionId;
12072
12256
  newScene.compositions = oldScene.compositions;
12073
12257
  newScene.items.forEach(function(item) {
@@ -12206,16 +12390,38 @@ var JSONConverter = /*#__PURE__*/ function() {
12206
12390
  id: mat.id
12207
12391
  };
12208
12392
  return data;
12209
- }),
12210
- rootBone: {
12211
- id: ""
12212
- }
12393
+ })
12213
12394
  };
12395
+ if (meshOptions.skin) {
12396
+ var parentItemId = component.item.id;
12397
+ for(var _iterator = _create_for_of_iterator_helper_loose(oldScene.items), _step; !(_step = _iterator()).done;){
12398
+ var item = _step.value;
12399
+ if (item.id === component.item.id) {
12400
+ parentItemId = item.parentId;
12401
+ }
12402
+ }
12403
+ if (parentItemId === component.item.id) {
12404
+ throw new Error("Can't item " + component.item);
12405
+ }
12406
+ var treeItem = this.treeInfo.getTreeItemByNodeId(parentItemId);
12407
+ var treeNodeList = this.treeInfo.getTreeNodeListByNodeId(parentItemId);
12408
+ if (!treeItem || !treeNodeList) {
12409
+ throw new Error("Can't find tree node list for " + component.item);
12410
+ }
12411
+ var rootBoneItem = this.setupBoneData(geometryData, meshOptions.skin, oldScene, treeItem, treeNodeList);
12412
+ meshComponent.rootBone = {
12413
+ id: rootBoneItem.id
12414
+ };
12415
+ }
12416
+ if (meshOptions.weights !== undefined) {
12417
+ meshComponent.morph = {
12418
+ weights: meshOptions.weights
12419
+ };
12420
+ }
12214
12421
  return meshComponent;
12215
12422
  };
12216
12423
  _proto.createItemsFromTreeComponent = function createItemsFromTreeComponent(component, newScene, oldScene) {
12217
12424
  var _this = this;
12218
- var _this_treeItemList;
12219
12425
  var treeItem = oldScene.items[0];
12220
12426
  oldScene.items.forEach(function(item) {
12221
12427
  if (item.id === component.item.id) {
@@ -12224,13 +12430,13 @@ var JSONConverter = /*#__PURE__*/ function() {
12224
12430
  });
12225
12431
  var treeComp = component;
12226
12432
  var treeData = treeComp.options.tree;
12227
- var treeItemList = [];
12228
- treeData.nodes.forEach(function(node) {
12433
+ var treeNodeList = [];
12434
+ treeData.nodes.forEach(function(node, index) {
12229
12435
  var _node_name;
12230
12436
  var item = {
12231
12437
  id: effects.generateGUID(),
12232
12438
  parentId: treeItem.id,
12233
- name: (_node_name = node.name) != null ? _node_name : "<unnamed>",
12439
+ name: (_node_name = node.name) != null ? _node_name : "node" + index,
12234
12440
  duration: treeItem.duration,
12235
12441
  // @ts-expect-error
12236
12442
  type: "ECS",
@@ -12245,14 +12451,14 @@ var JSONConverter = /*#__PURE__*/ function() {
12245
12451
  transform: _this.getTransformData(node.transform),
12246
12452
  components: []
12247
12453
  };
12248
- treeItemList.push(item);
12454
+ treeNodeList.push(item);
12249
12455
  newScene.items.push(item);
12250
12456
  });
12251
12457
  treeData.nodes.forEach(function(node, index) {
12252
12458
  var _node_children;
12253
- var item = treeItemList[index];
12459
+ var item = treeNodeList[index];
12254
12460
  (_node_children = node.children) == null ? void 0 : _node_children.forEach(function(child) {
12255
- var childItem = treeItemList[child];
12461
+ var childItem = treeNodeList[child];
12256
12462
  childItem.parentId = item.id;
12257
12463
  });
12258
12464
  });
@@ -12263,12 +12469,13 @@ var JSONConverter = /*#__PURE__*/ function() {
12263
12469
  var parentId = item.parentId.substring(0, index);
12264
12470
  var subIndex = +item.parentId.substring(index + 1);
12265
12471
  if (parentId === treeItem.id) {
12266
- item.parentId = treeItemList[subIndex].id;
12472
+ item.parentId = treeNodeList[subIndex].id;
12267
12473
  }
12268
12474
  }
12269
12475
  }
12270
12476
  });
12271
- (_this_treeItemList = this.treeItemList).push.apply(_this_treeItemList, [].concat(treeItemList));
12477
+ this.treeInfo.add(treeItem, treeNodeList);
12478
+ this.createAnimationComponent(treeData, treeItem, newScene, oldScene);
12272
12479
  };
12273
12480
  _proto.createLightComponent = function createLightComponent(component, scene) {
12274
12481
  var lightOptions = component.options;
@@ -12294,6 +12501,186 @@ var JSONConverter = /*#__PURE__*/ function() {
12294
12501
  }
12295
12502
  return lightComponent;
12296
12503
  };
12504
+ _proto.createAnimationComponent = function createAnimationComponent(treeOptions, treeItem, newScene, oldScene) {
12505
+ var _this = this;
12506
+ var animation = treeOptions.animation, animations = treeOptions.animations;
12507
+ var animationComponent = {
12508
+ id: effects.generateGUID(),
12509
+ dataType: effects.spec.DataType.AnimationComponent,
12510
+ item: {
12511
+ id: treeItem.id
12512
+ },
12513
+ animation: animation,
12514
+ animationClips: []
12515
+ };
12516
+ if (animations && animations.length) {
12517
+ // FIXME: calcuate tree item duration
12518
+ var bins = oldScene.bins;
12519
+ animations.forEach(function(anim) {
12520
+ var clipData = {
12521
+ id: effects.generateGUID(),
12522
+ name: anim.name,
12523
+ dataType: effects.spec.DataType.AnimationClip,
12524
+ positionCurves: [],
12525
+ rotationCurves: [],
12526
+ scaleCurves: [],
12527
+ floatCurves: []
12528
+ };
12529
+ var totalAnimationTime = 0;
12530
+ anim.tracks.forEach(function(track) {
12531
+ var inputArray = typedArrayFromBinary(bins, track.input);
12532
+ totalAnimationTime = Math.max(totalAnimationTime, inputArray[inputArray.length - 1]);
12533
+ });
12534
+ anim.tracks.forEach(function(track) {
12535
+ var inputArray = typedArrayFromBinary(bins, track.input);
12536
+ var outputArray = typedArrayFromBinary(bins, track.output);
12537
+ if (!_instanceof1(inputArray, Float32Array)) {
12538
+ throw new Error("Type of inputArray should be float32, " + inputArray);
12539
+ }
12540
+ if (!_instanceof1(outputArray, Float32Array)) {
12541
+ throw new Error("Type of outputArray should be float32, " + outputArray);
12542
+ }
12543
+ if (track.interpolation !== "LINEAR") {
12544
+ throw new Error("Invalid interpolation type " + track.interpolation);
12545
+ }
12546
+ if (track.path === "rotation") {
12547
+ var points = [];
12548
+ var controlPoints = [];
12549
+ var lineValue = [];
12550
+ for(var i = 0; i < inputArray.length; i++){
12551
+ points.push([
12552
+ outputArray[i * 4],
12553
+ outputArray[i * 4 + 1],
12554
+ outputArray[i * 4 + 2],
12555
+ outputArray[i * 4 + 3]
12556
+ ]);
12557
+ if (i > 0) {
12558
+ var p0 = Quaternion.fromArray(points[i - 1]);
12559
+ var p3 = Quaternion.fromArray(points[i]);
12560
+ var p1 = new Quaternion();
12561
+ var p2 = new Quaternion();
12562
+ p1.slerpQuaternions(p0, p3, 1 / 3);
12563
+ p2.slerpQuaternions(p0, p3, 2 / 3);
12564
+ controlPoints.push(p1.toArray());
12565
+ controlPoints.push(p2.toArray());
12566
+ }
12567
+ lineValue.push([
12568
+ effects.spec.BezierKeyframeType.LINE,
12569
+ [
12570
+ inputArray[i],
12571
+ i
12572
+ ]
12573
+ ]);
12574
+ }
12575
+ var node = _this.treeInfo.getTreeNode(treeItem.id, track.node);
12576
+ var path = _this.treeInfo.getNodePath(node.id);
12577
+ var keyFrames = [
12578
+ effects.spec.ValueType.BEZIER_CURVE_QUAT,
12579
+ [
12580
+ lineValue,
12581
+ points,
12582
+ controlPoints
12583
+ ]
12584
+ ];
12585
+ clipData.rotationCurves.push({
12586
+ path: path,
12587
+ keyFrames: keyFrames
12588
+ });
12589
+ } else if (track.path === "weights") {
12590
+ var node1 = _this.treeInfo.getTreeNode(treeItem.id, track.node);
12591
+ var path1 = _this.treeInfo.getNodePath(node1.id);
12592
+ if (node1.components.length === 0) {
12593
+ for(var i1 = 0; i1 < oldScene.items.length; i1++){
12594
+ var child = oldScene.items[i1];
12595
+ if (child.parentId === node1.id) {
12596
+ path1 += "/" + child.name;
12597
+ break;
12598
+ }
12599
+ }
12600
+ }
12601
+ var component = outputArray.length / inputArray.length;
12602
+ for(var c = 0; c < component; c++){
12603
+ var lineValue1 = [];
12604
+ for(var i2 = 0; i2 < inputArray.length; i2++){
12605
+ lineValue1.push([
12606
+ effects.spec.BezierKeyframeType.LINE,
12607
+ [
12608
+ inputArray[i2],
12609
+ outputArray[i2 * component + c]
12610
+ ]
12611
+ ]);
12612
+ }
12613
+ var keyFrames1 = [
12614
+ effects.spec.ValueType.BEZIER_CURVE,
12615
+ lineValue1
12616
+ ];
12617
+ clipData.floatCurves.push({
12618
+ path: path1,
12619
+ className: "ModelMeshComponent",
12620
+ property: "morphWeights." + c,
12621
+ keyFrames: keyFrames1
12622
+ });
12623
+ }
12624
+ } else {
12625
+ var points1 = [];
12626
+ var controlPoints1 = [];
12627
+ var lineValue2 = [];
12628
+ for(var i3 = 0; i3 < inputArray.length; i3++){
12629
+ points1.push([
12630
+ outputArray[i3 * 3],
12631
+ outputArray[i3 * 3 + 1],
12632
+ outputArray[i3 * 3 + 2]
12633
+ ]);
12634
+ if (i3 > 0) {
12635
+ var p01 = Vector3.fromArray(points1[i3 - 1]);
12636
+ var p31 = Vector3.fromArray(points1[i3]);
12637
+ var p11 = new Vector3().lerpVectors(p01, p31, 1 / 3);
12638
+ var p21 = new Vector3().lerpVectors(p01, p31, 2 / 3);
12639
+ controlPoints1.push(p11.toArray());
12640
+ controlPoints1.push(p21.toArray());
12641
+ }
12642
+ lineValue2.push([
12643
+ effects.spec.BezierKeyframeType.LINE,
12644
+ [
12645
+ inputArray[i3],
12646
+ i3
12647
+ ]
12648
+ ]);
12649
+ }
12650
+ var node2 = _this.treeInfo.getTreeNode(treeItem.id, track.node);
12651
+ var path2 = _this.treeInfo.getNodePath(node2.id);
12652
+ var keyFrames2 = [
12653
+ effects.spec.ValueType.BEZIER_CURVE_PATH,
12654
+ [
12655
+ lineValue2,
12656
+ points1,
12657
+ controlPoints1
12658
+ ]
12659
+ ];
12660
+ if (track.path === "translation") {
12661
+ clipData.positionCurves.push({
12662
+ path: path2,
12663
+ keyFrames: keyFrames2
12664
+ });
12665
+ } else {
12666
+ clipData.scaleCurves.push({
12667
+ path: path2,
12668
+ keyFrames: keyFrames2
12669
+ });
12670
+ }
12671
+ }
12672
+ });
12673
+ newScene.animations.push(clipData);
12674
+ animationComponent.animationClips.push({
12675
+ id: clipData.id
12676
+ });
12677
+ });
12678
+ }
12679
+ treeItem.components.push({
12680
+ id: animationComponent.id
12681
+ });
12682
+ newScene.components.push(animationComponent);
12683
+ };
12297
12684
  _proto.getMaterialData = function getMaterialData(material, scene) {
12298
12685
  if (material.type === effects.spec.MaterialType.unlit) {
12299
12686
  var floats = {};
@@ -12314,7 +12701,7 @@ var JSONConverter = /*#__PURE__*/ function() {
12314
12701
  shader: {
12315
12702
  id: UnlitShaderGUID
12316
12703
  },
12317
- stringTags: this.getStringTags(material),
12704
+ stringTags: {},
12318
12705
  macros: [],
12319
12706
  ints: {},
12320
12707
  floats: floats,
@@ -12322,6 +12709,7 @@ var JSONConverter = /*#__PURE__*/ function() {
12322
12709
  colors: colors,
12323
12710
  textures: textures
12324
12711
  };
12712
+ this.setupMaterial(material, newMaterial);
12325
12713
  return newMaterial;
12326
12714
  } else {
12327
12715
  var floats1 = {
@@ -12370,7 +12758,7 @@ var JSONConverter = /*#__PURE__*/ function() {
12370
12758
  shader: {
12371
12759
  id: PBRShaderGUID
12372
12760
  },
12373
- stringTags: this.getStringTags(material),
12761
+ stringTags: {},
12374
12762
  macros: [],
12375
12763
  ints: {},
12376
12764
  floats: floats1,
@@ -12378,29 +12766,39 @@ var JSONConverter = /*#__PURE__*/ function() {
12378
12766
  colors: colors1,
12379
12767
  textures: textures1
12380
12768
  };
12769
+ this.setupMaterial(material, newMaterial1);
12381
12770
  return newMaterial1;
12382
12771
  }
12383
12772
  };
12384
- _proto.getStringTags = function getStringTags(material) {
12385
- var stringTags = {};
12386
- var _material_depthMask;
12387
- stringTags["ZWrite"] = String((_material_depthMask = material.depthMask) != null ? _material_depthMask : true);
12388
- stringTags["ZTest"] = String(true);
12389
- if (material.blending === effects.spec.MaterialBlending.masked) {
12390
- stringTags["RenderType"] = exports.RenderType.Mask;
12391
- } else if (material.blending === effects.spec.MaterialBlending.translucent) {
12392
- stringTags["RenderType"] = exports.RenderType.Blend;
12773
+ _proto.setupMaterial = function setupMaterial(oldMat, newMat) {
12774
+ if (oldMat.blending === effects.spec.MaterialBlending.translucent) {
12775
+ newMat.stringTags["RenderType"] = effects.spec.RenderType.Transparent;
12393
12776
  } else {
12394
- stringTags["RenderType"] = exports.RenderType.Opaque;
12777
+ newMat.stringTags["RenderType"] = effects.spec.RenderType.Opaque;
12395
12778
  }
12396
- if (material.side === effects.spec.SideMode.BACK) {
12397
- stringTags["Cull"] = exports.CullMode.Back;
12398
- } else if (material.side === effects.spec.SideMode.DOUBLE) {
12399
- stringTags["Cull"] = exports.CullMode.Double;
12779
+ if (oldMat.blending === effects.spec.MaterialBlending.masked) {
12780
+ newMat.floats["AlphaClip"] = 1;
12781
+ var _oldMat_alphaCutOff;
12782
+ newMat.floats["_Cutoff"] = (_oldMat_alphaCutOff = oldMat.alphaCutOff) != null ? _oldMat_alphaCutOff : 0;
12400
12783
  } else {
12401
- stringTags["Cull"] = exports.CullMode.Front;
12784
+ newMat.floats["AlphaClip"] = 0;
12402
12785
  }
12403
- return stringTags;
12786
+ switch(oldMat.side){
12787
+ case effects.spec.SideMode.BACK:
12788
+ newMat.stringTags["RenderFace"] = effects.spec.RenderFace.Back;
12789
+ break;
12790
+ case effects.spec.SideMode.DOUBLE:
12791
+ newMat.stringTags["RenderFace"] = effects.spec.RenderFace.Both;
12792
+ break;
12793
+ default:
12794
+ newMat.stringTags["RenderFace"] = effects.spec.RenderFace.Front;
12795
+ }
12796
+ if (oldMat.type === effects.spec.MaterialType.pbr) {
12797
+ newMat.floats["_SpecularAA"] = oldMat.useSpecularAA ? 1 : 0;
12798
+ }
12799
+ var _oldMat_depthMask;
12800
+ newMat.stringTags["ZWrite"] = String((_oldMat_depthMask = oldMat.depthMask) != null ? _oldMat_depthMask : true);
12801
+ newMat.stringTags["ZTest"] = String(true);
12404
12802
  };
12405
12803
  _proto.getTextureData = function getTextureData(scene, floats, texIndex, texTransform) {
12406
12804
  var _scene_textures_texIndex_id;
@@ -12475,8 +12873,121 @@ var JSONConverter = /*#__PURE__*/ function() {
12475
12873
  }
12476
12874
  return result;
12477
12875
  };
12876
+ _proto.setupBoneData = function setupBoneData(geom, skin, oldScene, treeItem, treeNodeList) {
12877
+ var bins = oldScene.bins;
12878
+ var joints = skin.joints, skeleton = skin.skeleton, inverseBindMatrices = skin.inverseBindMatrices;
12879
+ if (!inverseBindMatrices) {
12880
+ throw new Error("inverseBindMatrices is undefined " + skin);
12881
+ }
12882
+ var bindMatrixArray = typedArrayFromBinary(bins, inverseBindMatrices);
12883
+ geom.inverseBindMatrices = Array.from(bindMatrixArray);
12884
+ var id2Node = {};
12885
+ var rootBoneItem = treeItem;
12886
+ if (skeleton !== undefined) {
12887
+ rootBoneItem = treeNodeList[skeleton];
12888
+ } else {
12889
+ console.warn("Root bone is missing");
12890
+ }
12891
+ joints.forEach(function(joint) {
12892
+ var node = treeNodeList[joint];
12893
+ if (node !== rootBoneItem && node.parentId === rootBoneItem.parentId) {
12894
+ console.error("Find invalid node for rootBoneItem and adjust rootBoneItem");
12895
+ rootBoneItem = treeItem;
12896
+ }
12897
+ });
12898
+ treeNodeList.forEach(function(node) {
12899
+ id2Node[node.id] = node;
12900
+ });
12901
+ geom.rootBoneName = rootBoneItem.name;
12902
+ var boneNames = [];
12903
+ joints.forEach(function(joint) {
12904
+ var currentItem = treeNodeList[joint];
12905
+ var nodeList = [];
12906
+ while(currentItem && currentItem != rootBoneItem){
12907
+ nodeList.push(currentItem.name);
12908
+ if (currentItem.parentId) {
12909
+ currentItem = id2Node[currentItem.parentId];
12910
+ } else {
12911
+ break;
12912
+ }
12913
+ }
12914
+ boneNames.push(nodeList.reverse().join("/"));
12915
+ });
12916
+ geom.boneNames = boneNames;
12917
+ return rootBoneItem;
12918
+ };
12478
12919
  return JSONConverter;
12479
12920
  }();
12921
+ var TreeInfo = /*#__PURE__*/ function() {
12922
+ function TreeInfo() {
12923
+ this.tree2NodeList = {};
12924
+ this.nodeList2Tree = {};
12925
+ this.nodeId2Node = {};
12926
+ this.node2Path = {};
12927
+ }
12928
+ var _proto = TreeInfo.prototype;
12929
+ _proto.add = function add(treeItem, treeNodeList) {
12930
+ var _this = this;
12931
+ if (this.tree2NodeList[treeItem.id]) {
12932
+ throw new Error("Find duplicate treeItem id: " + treeItem.id);
12933
+ }
12934
+ this.tree2NodeList[treeItem.id] = treeNodeList;
12935
+ treeNodeList.forEach(function(node) {
12936
+ if (_this.nodeList2Tree[node.id]) {
12937
+ throw new Error("Find duplicate tree node id: " + node.id);
12938
+ }
12939
+ _this.nodeList2Tree[node.id] = treeItem;
12940
+ _this.nodeId2Node[node.id] = node;
12941
+ });
12942
+ treeNodeList.forEach(function(node) {
12943
+ _this.setNodePath(node);
12944
+ });
12945
+ };
12946
+ _proto.setNodePath = function setNodePath(node) {
12947
+ if (node.parentId) {
12948
+ if (this.node2Path[node.parentId]) {
12949
+ this.node2Path[node.id] = this.node2Path[node.parentId] + "/" + node.name;
12950
+ } else if (this.nodeId2Node[node.parentId]) {
12951
+ this.setNodePath(this.nodeId2Node[node.parentId]);
12952
+ this.node2Path[node.id] = this.node2Path[node.parentId] + "/" + node.name;
12953
+ } else {
12954
+ this.node2Path[node.id] = node.name;
12955
+ }
12956
+ } else {
12957
+ this.node2Path[node.id] = node.name;
12958
+ }
12959
+ };
12960
+ _proto.getTreeNodeListByTreeId = function getTreeNodeListByTreeId(id) {
12961
+ return this.tree2NodeList[id];
12962
+ };
12963
+ _proto.getTreeNodeListByNodeId = function getTreeNodeListByNodeId(id) {
12964
+ var treeItem = this.nodeList2Tree[id];
12965
+ if (!treeItem) {
12966
+ throw new Error("Invalid id " + id);
12967
+ }
12968
+ return this.getTreeNodeListByTreeId(treeItem.id);
12969
+ };
12970
+ _proto.getTreeItemByNodeId = function getTreeItemByNodeId(id) {
12971
+ return this.nodeList2Tree[id];
12972
+ };
12973
+ _proto.getTreeNode = function getTreeNode(treeId, nodeIndex) {
12974
+ var nodeList = this.getTreeNodeListByTreeId(treeId);
12975
+ return nodeList[nodeIndex];
12976
+ };
12977
+ _proto.getAllTreeNodeList = function getAllTreeNodeList() {
12978
+ var _this = this;
12979
+ var nodeList = [];
12980
+ Object.keys(this.tree2NodeList).forEach(function(key) {
12981
+ var _nodeList;
12982
+ (_nodeList = nodeList).push.apply(_nodeList, [].concat(_this.tree2NodeList[key]));
12983
+ });
12984
+ return nodeList;
12985
+ };
12986
+ _proto.getNodePath = function getNodePath(id) {
12987
+ return this.node2Path[id];
12988
+ };
12989
+ return TreeInfo;
12990
+ }();
12480
12991
  function getGeometryDataFromOptions(geomOptions) {
12481
12992
  var vertexCount = 0;
12482
12993
  var verticesType = effects.spec.VertexFormatType.Float32;
@@ -12589,7 +13100,8 @@ function getGeometryDataFromPropsList(geomPropsList) {
12589
13100
  var scale = (_geomPropsList__indices_data_BYTES_PER_ELEMENT = (_geomPropsList__indices = geomPropsList[0].indices) == null ? void 0 : _geomPropsList__indices.data.BYTES_PER_ELEMENT) != null ? _geomPropsList__indices_data_BYTES_PER_ELEMENT : 1;
12590
13101
  subMeshes.push({
12591
13102
  offset: offset * scale,
12592
- count: count
13103
+ indexCount: count,
13104
+ vertexCount: count
12593
13105
  });
12594
13106
  if (i) {
12595
13107
  var geom0 = geomPropsList[0];
@@ -12836,7 +13348,9 @@ var vertexBufferSemanticMap = {
12836
13348
  a_Tangent: "TANGENT",
12837
13349
  a_Color: "COLOR",
12838
13350
  a_Joints: "JOINTS",
13351
+ a_Joint1: "JOINTS",
12839
13352
  a_Weights: "WEIGHTS",
13353
+ a_Weight1: "WEIGHTS",
12840
13354
  //
12841
13355
  a_Target_Position0: "POSITION_BS0",
12842
13356
  a_Target_Position1: "POSITION_BS1",
@@ -12858,8 +13372,11 @@ var vertexBufferSemanticMap = {
12858
13372
 
12859
13373
  effects.registerPlugin("tree", ModelTreePlugin, effects.VFXItem, true);
12860
13374
  effects.registerPlugin("model", ModelPlugin, effects.VFXItem);
12861
- var version = "2.0.0-alpha.12";
13375
+ var version = "2.0.0-alpha.13";
12862
13376
  effects.logger.info("plugin model version: " + version);
13377
+ if (version !== effects.version) {
13378
+ 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!");
13379
+ }
12863
13380
 
12864
13381
  exports.BoxMesh = BoxMesh;
12865
13382
  exports.CameraGestureHandlerImp = CameraGestureHandlerImp;