@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/loader.mjs CHANGED
@@ -3,10 +3,10 @@
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
- import { math, Transform, spec, PLAYER_OPTIONS_ENV_EDITOR, glContext, Texture, TextureSourceType, Material, Mesh, Geometry, GLSLVersion, addItem, removeItem, generateGUID, loadImage, effectsClass, VFXItem, ItemBehaviour, AbstractPlugin, registerPlugin, logger, TimelineComponent, HitTestType, RendererComponent, RenderPass, TextureLoadAction, DestroyOptions, RenderPassDestroyAttachmentType, Renderer, getDefaultTextureFactory, Player, glType2VertexFormatType, Downloader, getStandardJSON } from '@galacean/effects';
9
+ import { math, Transform, spec, PLAYER_OPTIONS_ENV_EDITOR, glContext, Texture, TextureSourceType, Material, Mesh, Geometry, GLSLVersion, addItem, removeItem, generateGUID, loadImage, effectsClass, VFXItem, ItemBehaviour, AbstractPlugin, registerPlugin, logger, version as version$1, HitTestType, RendererComponent, AnimationClip, RenderPass, TextureLoadAction, DestroyOptions, RenderPassDestroyAttachmentType, Renderer, getDefaultTextureFactory, Player, glType2VertexFormatType, Downloader, getStandardJSON } from '@galacean/effects';
10
10
 
11
11
  var Vector2 = math.Vector2, Vector3 = math.Vector3, Vector4 = math.Vector4, Matrix3 = math.Matrix3, Matrix4 = math.Matrix4, Color = math.Color, Euler = math.Euler, EulerOrder = math.EulerOrder, Quaternion = math.Quaternion, Box3 = math.Box3; math.Sphere; math.Ray; var DEG2RAD = math.DEG2RAD;
12
12
 
@@ -715,6 +715,41 @@ function _inherits(subClass, superClass) {
715
715
  if (superClass) _set_prototype_of(subClass, superClass);
716
716
  }
717
717
 
718
+ function _array_like_to_array(arr, len) {
719
+ if (len == null || len > arr.length) len = arr.length;
720
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
721
+ return arr2;
722
+ }
723
+
724
+ function _unsupported_iterable_to_array(o, minLen) {
725
+ if (!o) return;
726
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
727
+ var n = Object.prototype.toString.call(o).slice(8, -1);
728
+ if (n === "Object" && o.constructor) n = o.constructor.name;
729
+ if (n === "Map" || n === "Set") return Array.from(n);
730
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
731
+ }
732
+
733
+ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
734
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
735
+ if (it) return (it = it.call(o)).next.bind(it);
736
+ // Fallback for engines without symbol support
737
+ if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
738
+ if (it) o = it;
739
+ var i = 0;
740
+ return function() {
741
+ if (i >= o.length) return {
742
+ done: true
743
+ };
744
+ return {
745
+ done: false,
746
+ value: o[i++]
747
+ };
748
+ };
749
+ }
750
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
751
+ }
752
+
718
753
  var objectIndex = 1;
719
754
  /**
720
755
  * 抽象对象类,提供公共的成员变量和成员函数
@@ -918,7 +953,7 @@ var shadowPassFrag = "#define FEATURES\n#include <shadowCommon.vert.glsl>\n#incl
918
953
 
919
954
  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);}";
920
955
 
921
- 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);}";
956
+ 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);}";
922
957
 
923
958
  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";
924
959
 
@@ -1357,7 +1392,7 @@ var TextureDataMode;
1357
1392
  */ _this.skeleton = 0;
1358
1393
  /**
1359
1394
  * 关节索引
1360
- */ _this.jointList = [];
1395
+ */ _this.jointItem = [];
1361
1396
  /**
1362
1397
  * 逆绑定矩阵
1363
1398
  */ _this.inverseBindMatrices = [];
@@ -1372,27 +1407,26 @@ var TextureDataMode;
1372
1407
  var _proto = PSkin.prototype;
1373
1408
  /**
1374
1409
  * 创建蒙皮对象
1375
- * @param options - 蒙皮相关数据
1410
+ * @param props - 蒙皮相关数据
1376
1411
  * @param engine - 引擎对象
1377
- * @param parentItem - 场景树父元素
1378
- */ _proto.create = function create(options, engine, parentItem) {
1379
- var _options_name;
1380
- this.name = this.genName((_options_name = options.name) != null ? _options_name : "Unnamed skin");
1412
+ * @param rootBoneItem - 场景树父元素
1413
+ */ _proto.create = function create(props, engine, rootBoneItem) {
1414
+ var _props_rootBoneName;
1415
+ this.name = (_props_rootBoneName = props.rootBoneName) != null ? _props_rootBoneName : "Unnamed skin";
1381
1416
  this.type = PObjectType.skin;
1382
1417
  //
1383
- this.parentItem = parentItem;
1384
- var _options_skeleton;
1385
- this.skeleton = (_options_skeleton = options.skeleton) != null ? _options_skeleton : -1;
1386
- this.jointList = options.joints;
1418
+ this.rootBoneItem = rootBoneItem;
1419
+ this.skeleton = -1;
1420
+ this.jointItem = this.getJointItems(props, rootBoneItem);
1387
1421
  this.animationMatrices = [];
1388
1422
  //
1389
1423
  this.inverseBindMatrices = [];
1390
1424
  //
1391
1425
  this.textureDataMode = this.getTextureDataMode(this.getJointCount(), engine);
1392
- var matList = options.inverseBindMatrices;
1426
+ var matList = props.inverseBindMatrices;
1393
1427
  if (matList !== undefined && matList.length > 0) {
1394
- if (matList.length % 16 !== 0 || matList.length !== this.jointList.length * 16) {
1395
- throw new Error("Invalid array length, invert bind matrices " + matList.length + ", joint array " + this.jointList.length);
1428
+ if (matList.length % 16 !== 0 || matList.length !== this.jointItem.length * 16) {
1429
+ throw new Error("Invalid array length, invert bind matrices " + matList.length + ", joint array " + this.jointItem.length);
1396
1430
  }
1397
1431
  var matrixCount = matList.length / 16;
1398
1432
  for(var i = 0; i < matrixCount; i++){
@@ -1405,26 +1439,17 @@ var TextureDataMode;
1405
1439
  * 更新蒙皮矩阵
1406
1440
  */ _proto.updateSkinMatrices = function updateSkinMatrices() {
1407
1441
  var _this = this;
1408
- var _this_parentItem;
1409
1442
  this.animationMatrices = [];
1410
- var parentTree = (_this_parentItem = this.parentItem) == null ? void 0 : _this_parentItem.getComponent(ModelTreeComponent);
1411
- if (parentTree !== undefined) {
1412
- for(var i = 0; i < this.jointList.length; i++){
1413
- var joint = this.jointList[i];
1414
- var node = parentTree.content.getNodeById(joint);
1415
- // let parent = node?.transform.parentTransform;
1416
- // while(parent !== undefined){
1417
- // const pos = parent.position;
1418
- // parent.setPosition(pos[0], pos[1], pos[2]);
1419
- // parent = parent.parentTransform;
1420
- // }
1421
- if (node === undefined) {
1422
- console.error("Can't find joint " + joint + " in node tree " + this.parentItem + ".");
1423
- break;
1424
- }
1425
- var mat4 = node.transform.getWorldMatrix();
1426
- this.animationMatrices.push(mat4.clone());
1427
- }
1443
+ for(var i = 0; i < this.jointItem.length; i++){
1444
+ var node = this.jointItem[i];
1445
+ // let parent = node?.transform.parentTransform;
1446
+ // while(parent !== undefined){
1447
+ // const pos = parent.position;
1448
+ // parent.setPosition(pos[0], pos[1], pos[2]);
1449
+ // parent = parent.parentTransform;
1450
+ // }
1451
+ var mat4 = node.transform.getWorldMatrix();
1452
+ this.animationMatrices.push(mat4.clone());
1428
1453
  }
1429
1454
  if (this.animationMatrices.length === this.inverseBindMatrices.length) {
1430
1455
  this.animationMatrices.forEach(function(mat, index) {
@@ -1459,13 +1484,13 @@ var TextureDataMode;
1459
1484
  * 更新父元素
1460
1485
  * @param parentItem - 场景树父元素
1461
1486
  */ _proto.updateParentItem = function updateParentItem(parentItem) {
1462
- this.parentItem = parentItem;
1487
+ this.rootBoneItem = parentItem;
1463
1488
  };
1464
1489
  /**
1465
1490
  * 获取关节点数
1466
1491
  * @returns
1467
1492
  */ _proto.getJointCount = function getJointCount() {
1468
- return this.jointList.length;
1493
+ return this.jointItem.length;
1469
1494
  };
1470
1495
  /**
1471
1496
  * 是否纹理数据模式
@@ -1476,8 +1501,8 @@ var TextureDataMode;
1476
1501
  /**
1477
1502
  * 销毁
1478
1503
  */ _proto.dispose = function dispose() {
1479
- this.parentItem = undefined;
1480
- this.jointList = [];
1504
+ this.rootBoneItem = undefined;
1505
+ this.jointItem = [];
1481
1506
  this.inverseBindMatrices = [];
1482
1507
  this.animationMatrices = [];
1483
1508
  };
@@ -1499,6 +1524,38 @@ var TextureDataMode;
1499
1524
  return 0;
1500
1525
  }
1501
1526
  };
1527
+ _proto.getJointItems = function getJointItems(props, rootBoneItem) {
1528
+ var _props_boneNames;
1529
+ var name2Item = this.genNodeName(rootBoneItem);
1530
+ var jointItems = [];
1531
+ (_props_boneNames = props.boneNames) == null ? void 0 : _props_boneNames.forEach(function(boneName) {
1532
+ var node = name2Item[boneName];
1533
+ if (!node) {
1534
+ throw new Error("Can't find node of bone name " + boneName);
1535
+ }
1536
+ jointItems.push(node);
1537
+ });
1538
+ return jointItems;
1539
+ };
1540
+ _proto.genNodeName = function genNodeName(node) {
1541
+ var name2Item = {};
1542
+ var nameList = [];
1543
+ name2Item[""] = node;
1544
+ for(var _iterator = _create_for_of_iterator_helper_loose(node.children), _step; !(_step = _iterator()).done;){
1545
+ var child = _step.value;
1546
+ this.genNodeNameDFS(child, nameList, name2Item);
1547
+ }
1548
+ return name2Item;
1549
+ };
1550
+ _proto.genNodeNameDFS = function genNodeNameDFS(node, nameList, name2Item) {
1551
+ nameList.push(node.name);
1552
+ name2Item[nameList.join("/")] = node;
1553
+ for(var _iterator = _create_for_of_iterator_helper_loose(node.children), _step; !(_step = _iterator()).done;){
1554
+ var child = _step.value;
1555
+ this.genNodeNameDFS(child, nameList, name2Item);
1556
+ }
1557
+ nameList.pop();
1558
+ };
1502
1559
  return PSkin;
1503
1560
  }(PObject);
1504
1561
  /**
@@ -1516,6 +1573,10 @@ var TextureDataMode;
1516
1573
  * 范围要在 `[0, 8]` 之间,否则会报错。
1517
1574
  */ _this.morphWeightsLength = 0;
1518
1575
  /**
1576
+ * weights 数组的具体数据,来自动画控制器的每帧更新
1577
+ * 数组的长度必须和 morphWeightsLength 相同,否则会出错。
1578
+ */ _this.morphWeightsArray = [];
1579
+ /**
1519
1580
  * 是否有 Position 相关的 Morph 动画,shader 中需要知道
1520
1581
  */ _this.hasPositionMorph = false;
1521
1582
  /**
@@ -1557,7 +1618,7 @@ var TextureDataMode;
1557
1618
  });
1558
1619
  if (this.morphWeightsLength > 0) {
1559
1620
  // 有Morph动画,申请weights数据,判断各个属性是否有相关动画
1560
- this.morphWeightsArray = new Float32Array(this.morphWeightsLength);
1621
+ this.morphWeightsArray = Array(this.morphWeightsLength).fill(0);
1561
1622
  this.hasPositionMorph = positionCount == this.morphWeightsLength;
1562
1623
  this.hasNormalMorph = normalCount == this.morphWeightsLength;
1563
1624
  this.hasTangentMorph = tangentCount == this.morphWeightsLength;
@@ -1584,14 +1645,11 @@ var TextureDataMode;
1584
1645
  }
1585
1646
  return true;
1586
1647
  };
1587
- _proto.dispose = function dispose() {
1588
- this.morphWeightsArray = undefined;
1589
- };
1590
1648
  /**
1591
1649
  * 初始化 Morph target 的权重数组
1592
1650
  * @param weights - glTF Mesh 的权重数组,长度必须严格一致
1593
1651
  */ _proto.initWeights = function initWeights(weights) {
1594
- if (this.morphWeightsArray === undefined) {
1652
+ if (this.morphWeightsArray.length === 0) {
1595
1653
  return;
1596
1654
  }
1597
1655
  var morphWeights = this.morphWeightsArray;
@@ -1601,6 +1659,16 @@ var TextureDataMode;
1601
1659
  }
1602
1660
  });
1603
1661
  };
1662
+ _proto.updateWeights = function updateWeights(weights) {
1663
+ var _this = this;
1664
+ if (weights.length != this.morphWeightsArray.length) {
1665
+ console.error("Length of morph weights mismatch: input " + weights.length + ", internel " + this.morphWeightsArray.length);
1666
+ return;
1667
+ }
1668
+ weights.forEach(function(value, index) {
1669
+ return _this.morphWeightsArray[index] = value;
1670
+ });
1671
+ };
1604
1672
  /**
1605
1673
  * 当前状态是否有 Morph 动画:
1606
1674
  * 需要判断 weights 数组长度,以及 Position、Normal 和 Tangent 是否有动画
@@ -2657,6 +2725,7 @@ function _assert_this_initialized(self) {
2657
2725
  _this.parentIndex = proxy.getParentIndex();
2658
2726
  _this.parentItem = proxy.parentItem;
2659
2727
  _this.parentItemId = parentId;
2728
+ _this.rootBoneItem = meshData.rootBone;
2660
2729
  _this.skin = proxy.getSkinObj(engine);
2661
2730
  _this.morph = proxy.getMorphObj();
2662
2731
  _this.hide = proxy.isHide();
@@ -2699,6 +2768,9 @@ function _assert_this_initialized(self) {
2699
2768
  */ _proto.update = function update() {
2700
2769
  if (this.owner !== undefined) {
2701
2770
  this.transform.fromEffectsTransform(this.owner.transform);
2771
+ if (this.morph && this.morph.hasMorph() && this.owner.morphWeights.length > 0) {
2772
+ this.morph.updateWeights(this.owner.morphWeights);
2773
+ }
2702
2774
  }
2703
2775
  };
2704
2776
  /**
@@ -3330,12 +3402,8 @@ function _assert_this_initialized(self) {
3330
3402
  // Morph 相关的数据更新,仅需要更新 weights 数组
3331
3403
  var morph = this.morph;
3332
3404
  if (morph !== undefined && morph.hasMorph()) {
3333
- var morphWeights = morph.morphWeightsArray;
3334
- var morphWeightNumbers = [];
3335
- morphWeights.forEach(function(val) {
3336
- return morphWeightNumbers.push(val);
3337
- });
3338
- material.setFloats("_morphWeights", morphWeightNumbers);
3405
+ var morphWeights = morph.morphWeightsArray.slice();
3406
+ material.setFloats("_morphWeights", morphWeights);
3339
3407
  }
3340
3408
  };
3341
3409
  _proto.updateUniformsByScene = function updateUniformsByScene(sceneStates) {
@@ -3586,7 +3654,18 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
3586
3654
  this.itemData = itemData;
3587
3655
  this.parentItem = parentItem;
3588
3656
  this.data = itemData;
3589
- this.morphObj = new PMorph();
3657
+ this.geometry = itemData.geometry;
3658
+ this.rootBoneItem = itemData.rootBone;
3659
+ var morphObj = new PMorph();
3660
+ if (morphObj.create(this.geometry)) {
3661
+ var _itemData_morph;
3662
+ // 设置初始权重数组
3663
+ if ((_itemData_morph = itemData.morph) == null ? void 0 : _itemData_morph.weights) {
3664
+ var _itemData_morph1;
3665
+ morphObj.initWeights((_itemData_morph1 = itemData.morph) == null ? void 0 : _itemData_morph1.weights);
3666
+ }
3667
+ this.morphObj = morphObj;
3668
+ }
3590
3669
  }
3591
3670
  var _proto = EffectsMeshProxy.prototype;
3592
3671
  _proto.hasMorphTarget = function hasMorphTarget() {
@@ -3628,20 +3707,17 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
3628
3707
  return this.data.materials.length;
3629
3708
  };
3630
3709
  _proto.hasSkin = function hasSkin() {
3631
- // FIXME: skin
3632
- //return this.options.skin !== undefined;
3633
- return false;
3710
+ var skin = this.geometry.getSkinProps();
3711
+ return !!(skin.rootBoneName && skin.boneNames && skin.inverseBindMatrices && this.rootBoneItem);
3634
3712
  };
3635
3713
  _proto.getSkinOpts = function getSkinOpts() {
3636
- // FIXME: skin
3637
- //return this.options.skin;
3638
- return;
3714
+ return this.geometry.getSkinProps();
3639
3715
  };
3640
3716
  _proto.getSkinObj = function getSkinObj(engine) {
3641
3717
  var skin = this.getSkinOpts();
3642
- if (skin !== undefined) {
3718
+ if (skin.rootBoneName && skin.boneNames && skin.inverseBindMatrices && this.rootBoneItem) {
3643
3719
  var skinObj = new PSkin();
3644
- skinObj.create(skin, engine, this.parentItem);
3720
+ skinObj.create(skin, engine, this.rootBoneItem);
3645
3721
  return skinObj;
3646
3722
  }
3647
3723
  return undefined;
@@ -6898,8 +6974,11 @@ var CameraGestureHandlerImp = /*#__PURE__*/ function() {
6898
6974
 
6899
6975
  registerPlugin("tree", ModelTreePlugin, VFXItem, true);
6900
6976
  registerPlugin("model", ModelPlugin, VFXItem);
6901
- var version = "2.0.0-alpha.12";
6977
+ var version = "2.0.0-alpha.13";
6902
6978
  logger.info("plugin model version: " + version);
6979
+ if (version !== version$1) {
6980
+ 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!");
6981
+ }
6903
6982
 
6904
6983
  var ModelMeshComponent = /*#__PURE__*/ function(RendererComponent) {
6905
6984
  _inherits(ModelMeshComponent, RendererComponent);
@@ -6907,6 +6986,9 @@ var ModelMeshComponent = /*#__PURE__*/ function(RendererComponent) {
6907
6986
  var _this;
6908
6987
  _this = RendererComponent.call(this, engine) || this;
6909
6988
  /**
6989
+ * morph 动画权重
6990
+ */ _this.morphWeights = [];
6991
+ /**
6910
6992
  * 获取点击测试参数,根据元素包围盒进行相交测试,Mesh 对象会进行更加精确的点击测试
6911
6993
  * @param force - 是否强制进行点击测试
6912
6994
  * @returns 点击测试参数
@@ -7223,7 +7305,6 @@ var ModelCameraComponent = /*#__PURE__*/ function(ItemBehaviour) {
7223
7305
  */ _proto.start = function start() {
7224
7306
  this.createContent();
7225
7307
  this.item.type = VFX_ITEM_TYPE_3D;
7226
- this.timeline = this.item.getComponent(TimelineComponent);
7227
7308
  var scene = getSceneManager(this);
7228
7309
  scene == null ? void 0 : scene.addItem(this.content);
7229
7310
  this.updateMainCamera();
@@ -7275,19 +7356,11 @@ var ModelCameraComponent = /*#__PURE__*/ function(ItemBehaviour) {
7275
7356
  * @param position - 位置
7276
7357
  * @param rotation - 旋转
7277
7358
  */ _proto.setTransform = function setTransform(position, rotation) {
7278
- var _this_timeline_findTrack, _this_timeline;
7279
- var clip = (_this_timeline = this.timeline) == null ? void 0 : (_this_timeline_findTrack = _this_timeline.findTrack("AnimationTrack")) == null ? void 0 : _this_timeline_findTrack.findClip("AnimationTimelineClip");
7280
- if (position !== undefined) {
7359
+ if (position) {
7281
7360
  this.transform.setPosition(position.x, position.y, position.z);
7282
- if (clip) {
7283
- clip.playable.originalTransform.position = position.clone();
7284
- }
7285
7361
  }
7286
- if (rotation !== undefined) {
7362
+ if (rotation) {
7287
7363
  this.transform.setRotation(rotation.x, rotation.y, rotation.z);
7288
- if (clip) {
7289
- clip.playable.originalTransform.rotation = rotation.clone();
7290
- }
7291
7364
  }
7292
7365
  this.updateMainCamera();
7293
7366
  };
@@ -7296,6 +7369,155 @@ var ModelCameraComponent = /*#__PURE__*/ function(ItemBehaviour) {
7296
7369
  ModelCameraComponent = __decorate([
7297
7370
  effectsClass(spec.DataType.CameraComponent)
7298
7371
  ], ModelCameraComponent);
7372
+ var AnimationComponent = /*#__PURE__*/ function(ItemBehaviour) {
7373
+ _inherits(AnimationComponent, ItemBehaviour);
7374
+ function AnimationComponent(engine) {
7375
+ var _this;
7376
+ _this = ItemBehaviour.call(this, engine) || this;
7377
+ _this.elapsedTime = 0;
7378
+ _this.animation = -1;
7379
+ _this.clips = [];
7380
+ return _this;
7381
+ }
7382
+ var _proto = AnimationComponent.prototype;
7383
+ /**
7384
+ * 组件开始,需要创建内部对象和添加到场景管理器中
7385
+ */ _proto.start = function start() {
7386
+ this.elapsedTime = 0;
7387
+ this.item.type = VFX_ITEM_TYPE_3D;
7388
+ };
7389
+ /**
7390
+ * 组件更新,更新内部对象状态
7391
+ * @param dt - 更新间隔
7392
+ */ _proto.update = function update(dt) {
7393
+ this.elapsedTime += dt * 0.001;
7394
+ if (this.animation >= 0 && this.animation < this.clips.length) {
7395
+ this.clips[this.animation].sampleAnimation(this.item, this.elapsedTime);
7396
+ }
7397
+ };
7398
+ /**
7399
+ * 组件销毁
7400
+ */ _proto.onDestroy = function onDestroy() {};
7401
+ /**
7402
+ * 反序列化,记录传入参数
7403
+ * @param data - 组件参数
7404
+ */ _proto.fromData = function fromData(data) {
7405
+ var _this = this;
7406
+ ItemBehaviour.prototype.fromData.call(this, data);
7407
+ this.data = data;
7408
+ var _data_name;
7409
+ //
7410
+ this.name = (_data_name = data.name) != null ? _data_name : "<empty>";
7411
+ var _data_animation;
7412
+ this.animation = (_data_animation = data.animation) != null ? _data_animation : -1;
7413
+ this.clips = [];
7414
+ data.animationClips.forEach(function(clipData) {
7415
+ var clipObj = new ModelAnimationClip(_this.engine);
7416
+ clipObj.setFromAnimationClip(clipData);
7417
+ _this.clips.push(clipObj);
7418
+ });
7419
+ };
7420
+ return AnimationComponent;
7421
+ }(ItemBehaviour);
7422
+ AnimationComponent = __decorate([
7423
+ effectsClass(spec.DataType.AnimationComponent)
7424
+ ], AnimationComponent);
7425
+ var ModelAnimationClip = /*#__PURE__*/ function(AnimationClip) {
7426
+ _inherits(ModelAnimationClip, AnimationClip);
7427
+ function ModelAnimationClip() {
7428
+ var _this;
7429
+ _this = AnimationClip.apply(this, arguments) || this;
7430
+ _this.path2Node = {};
7431
+ return _this;
7432
+ }
7433
+ var _proto = ModelAnimationClip.prototype;
7434
+ _proto.sampleAnimation = function sampleAnimation(vfxItem, time) {
7435
+ var duration = vfxItem.duration;
7436
+ var life = Math.max(0, time) % duration;
7437
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.positionCurves), _step; !(_step = _iterator()).done;){
7438
+ var curve = _step.value;
7439
+ var maxTime = curve.keyFrames.getMaxTime();
7440
+ var value = curve.keyFrames.getValue(life % maxTime);
7441
+ var target = this.getTargetItem(vfxItem, curve.path);
7442
+ target == null ? void 0 : target.transform.setPosition(value.x, value.y, value.z);
7443
+ }
7444
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(this.rotationCurves), _step1; !(_step1 = _iterator1()).done;){
7445
+ var curve1 = _step1.value;
7446
+ var maxTime1 = curve1.keyFrames.getMaxTime();
7447
+ var value1 = curve1.keyFrames.getValue(life % maxTime1);
7448
+ var target1 = this.getTargetItem(vfxItem, curve1.path);
7449
+ target1 == null ? void 0 : target1.transform.setQuaternion(value1.x, value1.y, value1.z, value1.w);
7450
+ }
7451
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(this.scaleCurves), _step2; !(_step2 = _iterator2()).done;){
7452
+ var curve2 = _step2.value;
7453
+ var maxTime2 = curve2.keyFrames.getMaxTime();
7454
+ var value2 = curve2.keyFrames.getValue(life % maxTime2);
7455
+ var target2 = this.getTargetItem(vfxItem, curve2.path);
7456
+ target2 == null ? void 0 : target2.transform.setScale(value2.x, value2.y, value2.z);
7457
+ }
7458
+ for(var _iterator3 = _create_for_of_iterator_helper_loose(this.floatCurves), _step3; !(_step3 = _iterator3()).done;){
7459
+ var curve3 = _step3.value;
7460
+ var maxTime3 = curve3.keyFrames.getMaxTime();
7461
+ var value3 = curve3.keyFrames.getValue(life % maxTime3);
7462
+ var target3 = this.getTargetItem(vfxItem, curve3.path);
7463
+ if (curve3.className === "ModelMeshComponent") {
7464
+ var component = target3 == null ? void 0 : target3.getComponent(ModelMeshComponent);
7465
+ if (component) {
7466
+ var properties = curve3.property.split(".");
7467
+ setProperty(component, properties, value3);
7468
+ } else {
7469
+ console.error("Can't find mesh component");
7470
+ }
7471
+ } else {
7472
+ console.warn("Ignore curve: className " + curve3.className);
7473
+ }
7474
+ }
7475
+ };
7476
+ _proto.setFromAnimationClip = function setFromAnimationClip(clip) {
7477
+ this.positionCurves = clip.positionCurves.slice();
7478
+ this.rotationCurves = clip.rotationCurves.slice();
7479
+ this.scaleCurves = clip.scaleCurves.slice();
7480
+ this.floatCurves = clip.floatCurves.slice();
7481
+ };
7482
+ _proto.getTargetItem = function getTargetItem(rootItem, path) {
7483
+ if (this.path2Node[path]) {
7484
+ return this.path2Node[path];
7485
+ }
7486
+ var target = rootItem;
7487
+ var nameList = path.split("/");
7488
+ for(var _iterator = _create_for_of_iterator_helper_loose(nameList), _step; !(_step = _iterator()).done;){
7489
+ var name = _step.value;
7490
+ var findTag = false;
7491
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(target.children), _step1; !(_step1 = _iterator1()).done;){
7492
+ var child = _step1.value;
7493
+ if (child.name === name) {
7494
+ target = child;
7495
+ findTag = true;
7496
+ break;
7497
+ }
7498
+ }
7499
+ if (!findTag) {
7500
+ throw new Error("Can't find path in tree " + rootItem.id + ", " + path);
7501
+ }
7502
+ }
7503
+ this.path2Node[path] = target;
7504
+ return target;
7505
+ };
7506
+ return ModelAnimationClip;
7507
+ }(AnimationClip);
7508
+ function setProperty(obj, properties, value) {
7509
+ var len = properties.length;
7510
+ var current = obj;
7511
+ for(var i = 0; i < len - 1; i++){
7512
+ var propName = properties[i];
7513
+ if (!(propName in current) || typeof current[propName] !== "object") {
7514
+ console.error("Invalid properties " + properties);
7515
+ return;
7516
+ }
7517
+ current = current[propName];
7518
+ }
7519
+ current[properties[len - 1]] = value;
7520
+ }
7299
7521
 
7300
7522
  // 射线与带旋转的包围盒求交
7301
7523
  // function transformDirection (m: Matrix4, direction: Vector3) {
@@ -11450,44 +11672,9 @@ var GLTFHelper = /*#__PURE__*/ function() {
11450
11672
  return GLTFHelper;
11451
11673
  }();
11452
11674
 
11453
- function _array_like_to_array(arr, len) {
11454
- if (len == null || len > arr.length) len = arr.length;
11455
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
11456
- return arr2;
11457
- }
11458
-
11459
- function _unsupported_iterable_to_array(o, minLen) {
11460
- if (!o) return;
11461
- if (typeof o === "string") return _array_like_to_array(o, minLen);
11462
- var n = Object.prototype.toString.call(o).slice(8, -1);
11463
- if (n === "Object" && o.constructor) n = o.constructor.name;
11464
- if (n === "Map" || n === "Set") return Array.from(n);
11465
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
11466
- }
11467
-
11468
- function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
11469
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
11470
- if (it) return (it = it.call(o)).next.bind(it);
11471
- // Fallback for engines without symbol support
11472
- if (Array.isArray(o) || (it = _unsupported_iterable_to_array(o)) || allowArrayLike && o && typeof o.length === "number") {
11473
- if (it) o = it;
11474
- var i = 0;
11475
- return function() {
11476
- if (i >= o.length) return {
11477
- done: true
11478
- };
11479
- return {
11480
- done: false,
11481
- value: o[i++]
11482
- };
11483
- };
11484
- }
11485
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
11486
- }
11487
-
11488
11675
  var JSONConverter = /*#__PURE__*/ function() {
11489
11676
  function JSONConverter(player) {
11490
- this.treeItemList = [];
11677
+ this.treeInfo = new TreeInfo();
11491
11678
  this.engine = player.renderer.engine;
11492
11679
  this.renderer = player.renderer;
11493
11680
  this.downloader = new Downloader();
@@ -11556,7 +11743,7 @@ var JSONConverter = /*#__PURE__*/ function() {
11556
11743
  case 7:
11557
11744
  // @ts-expect-error
11558
11745
  oldScene.bins = binFiles;
11559
- newScene = {
11746
+ newScene = _extends({}, oldScene, {
11560
11747
  version: "3.0",
11561
11748
  playerVersion: {
11562
11749
  web: "3.0",
@@ -11564,18 +11751,14 @@ var JSONConverter = /*#__PURE__*/ function() {
11564
11751
  },
11565
11752
  type: "ge",
11566
11753
  compositions: [],
11567
- compositionId: oldScene.compositionId,
11568
11754
  images: [],
11569
- shapes: oldScene.shapes,
11570
- plugins: oldScene.plugins,
11571
11755
  textures: [],
11572
11756
  items: [],
11573
11757
  components: [],
11574
11758
  materials: [],
11575
11759
  shaders: [],
11576
11760
  geometries: []
11577
- };
11578
- _this.treeItemList = [];
11761
+ });
11579
11762
  _this.setImage(newScene, oldScene);
11580
11763
  return [
11581
11764
  4,
@@ -11706,8 +11889,6 @@ var JSONConverter = /*#__PURE__*/ function() {
11706
11889
  var comp = _step.value;
11707
11890
  if (comp.dataType === spec.DataType.SkyboxComponent) {
11708
11891
  newComponents.push(this.createSkyboxComponent(comp, newScene));
11709
- } else if (comp.dataType === spec.DataType.MeshComponent) {
11710
- newComponents.push(this.createMeshComponent(comp, newScene, oldScene));
11711
11892
  } else if (comp.dataType === spec.DataType.LightComponent) {
11712
11893
  newComponents.push(this.createLightComponent(comp, newScene));
11713
11894
  } else if (comp.dataType === spec.DataType.CameraComponent) {
@@ -11719,16 +11900,22 @@ var JSONConverter = /*#__PURE__*/ function() {
11719
11900
  treeComp.options.tree.animation = undefined;
11720
11901
  treeComp.options.tree.animations = undefined;
11721
11902
  newComponents.push(comp);
11722
- } else {
11903
+ } else if (comp.dataType !== spec.DataType.MeshComponent) {
11723
11904
  newComponents.push(comp);
11724
11905
  }
11725
11906
  }
11907
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(oldScene.components), _step1; !(_step1 = _iterator1()).done;){
11908
+ var comp1 = _step1.value;
11909
+ if (comp1.dataType === spec.DataType.MeshComponent) {
11910
+ newComponents.push(this.createMeshComponent(comp1, newScene, oldScene));
11911
+ }
11912
+ }
11726
11913
  };
11727
11914
  _proto.setItem = function setItem(newScene, oldScene) {};
11728
11915
  _proto.setComposition = function setComposition(newScene, oldScene) {
11729
11916
  var _newScene_items;
11730
11917
  newScene.items = oldScene.items;
11731
- (_newScene_items = newScene.items).push.apply(_newScene_items, [].concat(this.treeItemList));
11918
+ (_newScene_items = newScene.items).push.apply(_newScene_items, [].concat(this.treeInfo.getAllTreeNodeList()));
11732
11919
  newScene.compositionId = oldScene.compositionId;
11733
11920
  newScene.compositions = oldScene.compositions;
11734
11921
  newScene.items.forEach(function(item) {
@@ -11867,16 +12054,38 @@ var JSONConverter = /*#__PURE__*/ function() {
11867
12054
  id: mat.id
11868
12055
  };
11869
12056
  return data;
11870
- }),
11871
- rootBone: {
11872
- id: ""
11873
- }
12057
+ })
11874
12058
  };
12059
+ if (meshOptions.skin) {
12060
+ var parentItemId = component.item.id;
12061
+ for(var _iterator = _create_for_of_iterator_helper_loose(oldScene.items), _step; !(_step = _iterator()).done;){
12062
+ var item = _step.value;
12063
+ if (item.id === component.item.id) {
12064
+ parentItemId = item.parentId;
12065
+ }
12066
+ }
12067
+ if (parentItemId === component.item.id) {
12068
+ throw new Error("Can't item " + component.item);
12069
+ }
12070
+ var treeItem = this.treeInfo.getTreeItemByNodeId(parentItemId);
12071
+ var treeNodeList = this.treeInfo.getTreeNodeListByNodeId(parentItemId);
12072
+ if (!treeItem || !treeNodeList) {
12073
+ throw new Error("Can't find tree node list for " + component.item);
12074
+ }
12075
+ var rootBoneItem = this.setupBoneData(geometryData, meshOptions.skin, oldScene, treeItem, treeNodeList);
12076
+ meshComponent.rootBone = {
12077
+ id: rootBoneItem.id
12078
+ };
12079
+ }
12080
+ if (meshOptions.weights !== undefined) {
12081
+ meshComponent.morph = {
12082
+ weights: meshOptions.weights
12083
+ };
12084
+ }
11875
12085
  return meshComponent;
11876
12086
  };
11877
12087
  _proto.createItemsFromTreeComponent = function createItemsFromTreeComponent(component, newScene, oldScene) {
11878
12088
  var _this = this;
11879
- var _this_treeItemList;
11880
12089
  var treeItem = oldScene.items[0];
11881
12090
  oldScene.items.forEach(function(item) {
11882
12091
  if (item.id === component.item.id) {
@@ -11885,13 +12094,13 @@ var JSONConverter = /*#__PURE__*/ function() {
11885
12094
  });
11886
12095
  var treeComp = component;
11887
12096
  var treeData = treeComp.options.tree;
11888
- var treeItemList = [];
11889
- treeData.nodes.forEach(function(node) {
12097
+ var treeNodeList = [];
12098
+ treeData.nodes.forEach(function(node, index) {
11890
12099
  var _node_name;
11891
12100
  var item = {
11892
12101
  id: generateGUID(),
11893
12102
  parentId: treeItem.id,
11894
- name: (_node_name = node.name) != null ? _node_name : "<unnamed>",
12103
+ name: (_node_name = node.name) != null ? _node_name : "node" + index,
11895
12104
  duration: treeItem.duration,
11896
12105
  // @ts-expect-error
11897
12106
  type: "ECS",
@@ -11906,14 +12115,14 @@ var JSONConverter = /*#__PURE__*/ function() {
11906
12115
  transform: _this.getTransformData(node.transform),
11907
12116
  components: []
11908
12117
  };
11909
- treeItemList.push(item);
12118
+ treeNodeList.push(item);
11910
12119
  newScene.items.push(item);
11911
12120
  });
11912
12121
  treeData.nodes.forEach(function(node, index) {
11913
12122
  var _node_children;
11914
- var item = treeItemList[index];
12123
+ var item = treeNodeList[index];
11915
12124
  (_node_children = node.children) == null ? void 0 : _node_children.forEach(function(child) {
11916
- var childItem = treeItemList[child];
12125
+ var childItem = treeNodeList[child];
11917
12126
  childItem.parentId = item.id;
11918
12127
  });
11919
12128
  });
@@ -11924,12 +12133,13 @@ var JSONConverter = /*#__PURE__*/ function() {
11924
12133
  var parentId = item.parentId.substring(0, index);
11925
12134
  var subIndex = +item.parentId.substring(index + 1);
11926
12135
  if (parentId === treeItem.id) {
11927
- item.parentId = treeItemList[subIndex].id;
12136
+ item.parentId = treeNodeList[subIndex].id;
11928
12137
  }
11929
12138
  }
11930
12139
  }
11931
12140
  });
11932
- (_this_treeItemList = this.treeItemList).push.apply(_this_treeItemList, [].concat(treeItemList));
12141
+ this.treeInfo.add(treeItem, treeNodeList);
12142
+ this.createAnimationComponent(treeData, treeItem, newScene, oldScene);
11933
12143
  };
11934
12144
  _proto.createLightComponent = function createLightComponent(component, scene) {
11935
12145
  var lightOptions = component.options;
@@ -11955,6 +12165,186 @@ var JSONConverter = /*#__PURE__*/ function() {
11955
12165
  }
11956
12166
  return lightComponent;
11957
12167
  };
12168
+ _proto.createAnimationComponent = function createAnimationComponent(treeOptions, treeItem, newScene, oldScene) {
12169
+ var _this = this;
12170
+ var animation = treeOptions.animation, animations = treeOptions.animations;
12171
+ var animationComponent = {
12172
+ id: generateGUID(),
12173
+ dataType: spec.DataType.AnimationComponent,
12174
+ item: {
12175
+ id: treeItem.id
12176
+ },
12177
+ animation: animation,
12178
+ animationClips: []
12179
+ };
12180
+ if (animations && animations.length) {
12181
+ // FIXME: calcuate tree item duration
12182
+ var bins = oldScene.bins;
12183
+ animations.forEach(function(anim) {
12184
+ var clipData = {
12185
+ id: generateGUID(),
12186
+ name: anim.name,
12187
+ dataType: spec.DataType.AnimationClip,
12188
+ positionCurves: [],
12189
+ rotationCurves: [],
12190
+ scaleCurves: [],
12191
+ floatCurves: []
12192
+ };
12193
+ var totalAnimationTime = 0;
12194
+ anim.tracks.forEach(function(track) {
12195
+ var inputArray = typedArrayFromBinary(bins, track.input);
12196
+ totalAnimationTime = Math.max(totalAnimationTime, inputArray[inputArray.length - 1]);
12197
+ });
12198
+ anim.tracks.forEach(function(track) {
12199
+ var inputArray = typedArrayFromBinary(bins, track.input);
12200
+ var outputArray = typedArrayFromBinary(bins, track.output);
12201
+ if (!_instanceof1(inputArray, Float32Array)) {
12202
+ throw new Error("Type of inputArray should be float32, " + inputArray);
12203
+ }
12204
+ if (!_instanceof1(outputArray, Float32Array)) {
12205
+ throw new Error("Type of outputArray should be float32, " + outputArray);
12206
+ }
12207
+ if (track.interpolation !== "LINEAR") {
12208
+ throw new Error("Invalid interpolation type " + track.interpolation);
12209
+ }
12210
+ if (track.path === "rotation") {
12211
+ var points = [];
12212
+ var controlPoints = [];
12213
+ var lineValue = [];
12214
+ for(var i = 0; i < inputArray.length; i++){
12215
+ points.push([
12216
+ outputArray[i * 4],
12217
+ outputArray[i * 4 + 1],
12218
+ outputArray[i * 4 + 2],
12219
+ outputArray[i * 4 + 3]
12220
+ ]);
12221
+ if (i > 0) {
12222
+ var p0 = Quaternion.fromArray(points[i - 1]);
12223
+ var p3 = Quaternion.fromArray(points[i]);
12224
+ var p1 = new Quaternion();
12225
+ var p2 = new Quaternion();
12226
+ p1.slerpQuaternions(p0, p3, 1 / 3);
12227
+ p2.slerpQuaternions(p0, p3, 2 / 3);
12228
+ controlPoints.push(p1.toArray());
12229
+ controlPoints.push(p2.toArray());
12230
+ }
12231
+ lineValue.push([
12232
+ spec.BezierKeyframeType.LINE,
12233
+ [
12234
+ inputArray[i],
12235
+ i
12236
+ ]
12237
+ ]);
12238
+ }
12239
+ var node = _this.treeInfo.getTreeNode(treeItem.id, track.node);
12240
+ var path = _this.treeInfo.getNodePath(node.id);
12241
+ var keyFrames = [
12242
+ spec.ValueType.BEZIER_CURVE_QUAT,
12243
+ [
12244
+ lineValue,
12245
+ points,
12246
+ controlPoints
12247
+ ]
12248
+ ];
12249
+ clipData.rotationCurves.push({
12250
+ path: path,
12251
+ keyFrames: keyFrames
12252
+ });
12253
+ } else if (track.path === "weights") {
12254
+ var node1 = _this.treeInfo.getTreeNode(treeItem.id, track.node);
12255
+ var path1 = _this.treeInfo.getNodePath(node1.id);
12256
+ if (node1.components.length === 0) {
12257
+ for(var i1 = 0; i1 < oldScene.items.length; i1++){
12258
+ var child = oldScene.items[i1];
12259
+ if (child.parentId === node1.id) {
12260
+ path1 += "/" + child.name;
12261
+ break;
12262
+ }
12263
+ }
12264
+ }
12265
+ var component = outputArray.length / inputArray.length;
12266
+ for(var c = 0; c < component; c++){
12267
+ var lineValue1 = [];
12268
+ for(var i2 = 0; i2 < inputArray.length; i2++){
12269
+ lineValue1.push([
12270
+ spec.BezierKeyframeType.LINE,
12271
+ [
12272
+ inputArray[i2],
12273
+ outputArray[i2 * component + c]
12274
+ ]
12275
+ ]);
12276
+ }
12277
+ var keyFrames1 = [
12278
+ spec.ValueType.BEZIER_CURVE,
12279
+ lineValue1
12280
+ ];
12281
+ clipData.floatCurves.push({
12282
+ path: path1,
12283
+ className: "ModelMeshComponent",
12284
+ property: "morphWeights." + c,
12285
+ keyFrames: keyFrames1
12286
+ });
12287
+ }
12288
+ } else {
12289
+ var points1 = [];
12290
+ var controlPoints1 = [];
12291
+ var lineValue2 = [];
12292
+ for(var i3 = 0; i3 < inputArray.length; i3++){
12293
+ points1.push([
12294
+ outputArray[i3 * 3],
12295
+ outputArray[i3 * 3 + 1],
12296
+ outputArray[i3 * 3 + 2]
12297
+ ]);
12298
+ if (i3 > 0) {
12299
+ var p01 = Vector3.fromArray(points1[i3 - 1]);
12300
+ var p31 = Vector3.fromArray(points1[i3]);
12301
+ var p11 = new Vector3().lerpVectors(p01, p31, 1 / 3);
12302
+ var p21 = new Vector3().lerpVectors(p01, p31, 2 / 3);
12303
+ controlPoints1.push(p11.toArray());
12304
+ controlPoints1.push(p21.toArray());
12305
+ }
12306
+ lineValue2.push([
12307
+ spec.BezierKeyframeType.LINE,
12308
+ [
12309
+ inputArray[i3],
12310
+ i3
12311
+ ]
12312
+ ]);
12313
+ }
12314
+ var node2 = _this.treeInfo.getTreeNode(treeItem.id, track.node);
12315
+ var path2 = _this.treeInfo.getNodePath(node2.id);
12316
+ var keyFrames2 = [
12317
+ spec.ValueType.BEZIER_CURVE_PATH,
12318
+ [
12319
+ lineValue2,
12320
+ points1,
12321
+ controlPoints1
12322
+ ]
12323
+ ];
12324
+ if (track.path === "translation") {
12325
+ clipData.positionCurves.push({
12326
+ path: path2,
12327
+ keyFrames: keyFrames2
12328
+ });
12329
+ } else {
12330
+ clipData.scaleCurves.push({
12331
+ path: path2,
12332
+ keyFrames: keyFrames2
12333
+ });
12334
+ }
12335
+ }
12336
+ });
12337
+ newScene.animations.push(clipData);
12338
+ animationComponent.animationClips.push({
12339
+ id: clipData.id
12340
+ });
12341
+ });
12342
+ }
12343
+ treeItem.components.push({
12344
+ id: animationComponent.id
12345
+ });
12346
+ newScene.components.push(animationComponent);
12347
+ };
11958
12348
  _proto.getMaterialData = function getMaterialData(material, scene) {
11959
12349
  if (material.type === spec.MaterialType.unlit) {
11960
12350
  var floats = {};
@@ -11975,7 +12365,7 @@ var JSONConverter = /*#__PURE__*/ function() {
11975
12365
  shader: {
11976
12366
  id: UnlitShaderGUID
11977
12367
  },
11978
- stringTags: this.getStringTags(material),
12368
+ stringTags: {},
11979
12369
  macros: [],
11980
12370
  ints: {},
11981
12371
  floats: floats,
@@ -11983,6 +12373,7 @@ var JSONConverter = /*#__PURE__*/ function() {
11983
12373
  colors: colors,
11984
12374
  textures: textures
11985
12375
  };
12376
+ this.setupMaterial(material, newMaterial);
11986
12377
  return newMaterial;
11987
12378
  } else {
11988
12379
  var floats1 = {
@@ -12031,7 +12422,7 @@ var JSONConverter = /*#__PURE__*/ function() {
12031
12422
  shader: {
12032
12423
  id: PBRShaderGUID
12033
12424
  },
12034
- stringTags: this.getStringTags(material),
12425
+ stringTags: {},
12035
12426
  macros: [],
12036
12427
  ints: {},
12037
12428
  floats: floats1,
@@ -12039,29 +12430,39 @@ var JSONConverter = /*#__PURE__*/ function() {
12039
12430
  colors: colors1,
12040
12431
  textures: textures1
12041
12432
  };
12433
+ this.setupMaterial(material, newMaterial1);
12042
12434
  return newMaterial1;
12043
12435
  }
12044
12436
  };
12045
- _proto.getStringTags = function getStringTags(material) {
12046
- var stringTags = {};
12047
- var _material_depthMask;
12048
- stringTags["ZWrite"] = String((_material_depthMask = material.depthMask) != null ? _material_depthMask : true);
12049
- stringTags["ZTest"] = String(true);
12050
- if (material.blending === spec.MaterialBlending.masked) {
12051
- stringTags["RenderType"] = RenderType.Mask;
12052
- } else if (material.blending === spec.MaterialBlending.translucent) {
12053
- stringTags["RenderType"] = RenderType.Blend;
12437
+ _proto.setupMaterial = function setupMaterial(oldMat, newMat) {
12438
+ if (oldMat.blending === spec.MaterialBlending.translucent) {
12439
+ newMat.stringTags["RenderType"] = spec.RenderType.Transparent;
12054
12440
  } else {
12055
- stringTags["RenderType"] = RenderType.Opaque;
12441
+ newMat.stringTags["RenderType"] = spec.RenderType.Opaque;
12056
12442
  }
12057
- if (material.side === spec.SideMode.BACK) {
12058
- stringTags["Cull"] = CullMode.Back;
12059
- } else if (material.side === spec.SideMode.DOUBLE) {
12060
- stringTags["Cull"] = CullMode.Double;
12443
+ if (oldMat.blending === spec.MaterialBlending.masked) {
12444
+ newMat.floats["AlphaClip"] = 1;
12445
+ var _oldMat_alphaCutOff;
12446
+ newMat.floats["_Cutoff"] = (_oldMat_alphaCutOff = oldMat.alphaCutOff) != null ? _oldMat_alphaCutOff : 0;
12061
12447
  } else {
12062
- stringTags["Cull"] = CullMode.Front;
12448
+ newMat.floats["AlphaClip"] = 0;
12063
12449
  }
12064
- return stringTags;
12450
+ switch(oldMat.side){
12451
+ case spec.SideMode.BACK:
12452
+ newMat.stringTags["RenderFace"] = spec.RenderFace.Back;
12453
+ break;
12454
+ case spec.SideMode.DOUBLE:
12455
+ newMat.stringTags["RenderFace"] = spec.RenderFace.Both;
12456
+ break;
12457
+ default:
12458
+ newMat.stringTags["RenderFace"] = spec.RenderFace.Front;
12459
+ }
12460
+ if (oldMat.type === spec.MaterialType.pbr) {
12461
+ newMat.floats["_SpecularAA"] = oldMat.useSpecularAA ? 1 : 0;
12462
+ }
12463
+ var _oldMat_depthMask;
12464
+ newMat.stringTags["ZWrite"] = String((_oldMat_depthMask = oldMat.depthMask) != null ? _oldMat_depthMask : true);
12465
+ newMat.stringTags["ZTest"] = String(true);
12065
12466
  };
12066
12467
  _proto.getTextureData = function getTextureData(scene, floats, texIndex, texTransform) {
12067
12468
  var _scene_textures_texIndex_id;
@@ -12136,8 +12537,121 @@ var JSONConverter = /*#__PURE__*/ function() {
12136
12537
  }
12137
12538
  return result;
12138
12539
  };
12540
+ _proto.setupBoneData = function setupBoneData(geom, skin, oldScene, treeItem, treeNodeList) {
12541
+ var bins = oldScene.bins;
12542
+ var joints = skin.joints, skeleton = skin.skeleton, inverseBindMatrices = skin.inverseBindMatrices;
12543
+ if (!inverseBindMatrices) {
12544
+ throw new Error("inverseBindMatrices is undefined " + skin);
12545
+ }
12546
+ var bindMatrixArray = typedArrayFromBinary(bins, inverseBindMatrices);
12547
+ geom.inverseBindMatrices = Array.from(bindMatrixArray);
12548
+ var id2Node = {};
12549
+ var rootBoneItem = treeItem;
12550
+ if (skeleton !== undefined) {
12551
+ rootBoneItem = treeNodeList[skeleton];
12552
+ } else {
12553
+ console.warn("Root bone is missing");
12554
+ }
12555
+ joints.forEach(function(joint) {
12556
+ var node = treeNodeList[joint];
12557
+ if (node !== rootBoneItem && node.parentId === rootBoneItem.parentId) {
12558
+ console.error("Find invalid node for rootBoneItem and adjust rootBoneItem");
12559
+ rootBoneItem = treeItem;
12560
+ }
12561
+ });
12562
+ treeNodeList.forEach(function(node) {
12563
+ id2Node[node.id] = node;
12564
+ });
12565
+ geom.rootBoneName = rootBoneItem.name;
12566
+ var boneNames = [];
12567
+ joints.forEach(function(joint) {
12568
+ var currentItem = treeNodeList[joint];
12569
+ var nodeList = [];
12570
+ while(currentItem && currentItem != rootBoneItem){
12571
+ nodeList.push(currentItem.name);
12572
+ if (currentItem.parentId) {
12573
+ currentItem = id2Node[currentItem.parentId];
12574
+ } else {
12575
+ break;
12576
+ }
12577
+ }
12578
+ boneNames.push(nodeList.reverse().join("/"));
12579
+ });
12580
+ geom.boneNames = boneNames;
12581
+ return rootBoneItem;
12582
+ };
12139
12583
  return JSONConverter;
12140
12584
  }();
12585
+ var TreeInfo = /*#__PURE__*/ function() {
12586
+ function TreeInfo() {
12587
+ this.tree2NodeList = {};
12588
+ this.nodeList2Tree = {};
12589
+ this.nodeId2Node = {};
12590
+ this.node2Path = {};
12591
+ }
12592
+ var _proto = TreeInfo.prototype;
12593
+ _proto.add = function add(treeItem, treeNodeList) {
12594
+ var _this = this;
12595
+ if (this.tree2NodeList[treeItem.id]) {
12596
+ throw new Error("Find duplicate treeItem id: " + treeItem.id);
12597
+ }
12598
+ this.tree2NodeList[treeItem.id] = treeNodeList;
12599
+ treeNodeList.forEach(function(node) {
12600
+ if (_this.nodeList2Tree[node.id]) {
12601
+ throw new Error("Find duplicate tree node id: " + node.id);
12602
+ }
12603
+ _this.nodeList2Tree[node.id] = treeItem;
12604
+ _this.nodeId2Node[node.id] = node;
12605
+ });
12606
+ treeNodeList.forEach(function(node) {
12607
+ _this.setNodePath(node);
12608
+ });
12609
+ };
12610
+ _proto.setNodePath = function setNodePath(node) {
12611
+ if (node.parentId) {
12612
+ if (this.node2Path[node.parentId]) {
12613
+ this.node2Path[node.id] = this.node2Path[node.parentId] + "/" + node.name;
12614
+ } else if (this.nodeId2Node[node.parentId]) {
12615
+ this.setNodePath(this.nodeId2Node[node.parentId]);
12616
+ this.node2Path[node.id] = this.node2Path[node.parentId] + "/" + node.name;
12617
+ } else {
12618
+ this.node2Path[node.id] = node.name;
12619
+ }
12620
+ } else {
12621
+ this.node2Path[node.id] = node.name;
12622
+ }
12623
+ };
12624
+ _proto.getTreeNodeListByTreeId = function getTreeNodeListByTreeId(id) {
12625
+ return this.tree2NodeList[id];
12626
+ };
12627
+ _proto.getTreeNodeListByNodeId = function getTreeNodeListByNodeId(id) {
12628
+ var treeItem = this.nodeList2Tree[id];
12629
+ if (!treeItem) {
12630
+ throw new Error("Invalid id " + id);
12631
+ }
12632
+ return this.getTreeNodeListByTreeId(treeItem.id);
12633
+ };
12634
+ _proto.getTreeItemByNodeId = function getTreeItemByNodeId(id) {
12635
+ return this.nodeList2Tree[id];
12636
+ };
12637
+ _proto.getTreeNode = function getTreeNode(treeId, nodeIndex) {
12638
+ var nodeList = this.getTreeNodeListByTreeId(treeId);
12639
+ return nodeList[nodeIndex];
12640
+ };
12641
+ _proto.getAllTreeNodeList = function getAllTreeNodeList() {
12642
+ var _this = this;
12643
+ var nodeList = [];
12644
+ Object.keys(this.tree2NodeList).forEach(function(key) {
12645
+ var _nodeList;
12646
+ (_nodeList = nodeList).push.apply(_nodeList, [].concat(_this.tree2NodeList[key]));
12647
+ });
12648
+ return nodeList;
12649
+ };
12650
+ _proto.getNodePath = function getNodePath(id) {
12651
+ return this.node2Path[id];
12652
+ };
12653
+ return TreeInfo;
12654
+ }();
12141
12655
  function getGeometryDataFromOptions(geomOptions) {
12142
12656
  var vertexCount = 0;
12143
12657
  var verticesType = spec.VertexFormatType.Float32;
@@ -12250,7 +12764,8 @@ function getGeometryDataFromPropsList(geomPropsList) {
12250
12764
  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;
12251
12765
  subMeshes.push({
12252
12766
  offset: offset * scale,
12253
- count: count
12767
+ indexCount: count,
12768
+ vertexCount: count
12254
12769
  });
12255
12770
  if (i) {
12256
12771
  var geom0 = geomPropsList[0];
@@ -12497,7 +13012,9 @@ var vertexBufferSemanticMap = {
12497
13012
  a_Tangent: "TANGENT",
12498
13013
  a_Color: "COLOR",
12499
13014
  a_Joints: "JOINTS",
13015
+ a_Joint1: "JOINTS",
12500
13016
  a_Weights: "WEIGHTS",
13017
+ a_Weight1: "WEIGHTS",
12501
13018
  //
12502
13019
  a_Target_Position0: "POSITION_BS0",
12503
13020
  a_Target_Position1: "POSITION_BS1",