@galacean/effects-plugin-model 2.10.0-alpha.1 → 2.10.0-alpha.3

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,11 +3,11 @@
3
3
  * Description: Galacean Effects player model plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 飂兮
6
- * Version: v2.10.0-alpha.1
6
+ * Version: v2.10.0-alpha.3
7
7
  */
8
8
 
9
9
  import * as EFFECTS from '@galacean/effects';
10
- import { math, Transform, spec, PLAYER_OPTIONS_ENV_EDITOR, glContext, Material, Mesh, Geometry, ShaderFactory, GLSLVersion, VFXItem, Plugin, effectsClass, Behaviour, registerPlugin, logger, RendererComponent, HitTestType, AnimationClip, TextureSourceType, Texture, DestroyOptions, RenderPassDestroyAttachmentType, getDefaultTextureFactory, Player, loadImage, generateGUID, addItem, removeItem, glType2VertexFormatType, Downloader, getStandardJSON, isObject } from '@galacean/effects';
10
+ import { math, Transform, spec, PLAYER_OPTIONS_ENV_EDITOR, VertexBuffer, glContext, Material, Mesh, Geometry, ShaderFactory, GLSLVersion, VFXItem, Plugin, effectsClass, Behaviour, registerPlugin, logger, RendererComponent, HitTestType, AnimationClip, TextureSourceType, Texture, DestroyOptions, RenderPassDestroyAttachmentType, getDefaultTextureFactory, Player, loadImage, generateGUID, addItem, removeItem, glType2VertexFormatType, Downloader, getStandardJSON, isObject } from '@galacean/effects';
11
11
 
12
12
  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;
13
13
 
@@ -1110,16 +1110,15 @@ function _wrap_native_super(Class) {
1110
1110
  3,
1111
1111
  7
1112
1112
  ]);
1113
+ var _obj;
1113
1114
  return {
1114
- attributes: {
1115
- aPos: {
1116
- type: glContext.FLOAT,
1117
- size: 1,
1118
- data: data,
1119
- stride: Float32Array.BYTES_PER_ELEMENT,
1120
- offset: 0
1121
- }
1122
- },
1115
+ attributes: (_obj = {}, _obj[VertexBuffer.PositionKind] = {
1116
+ type: glContext.FLOAT,
1117
+ size: 1,
1118
+ data: data,
1119
+ stride: Float32Array.BYTES_PER_ELEMENT,
1120
+ offset: 0
1121
+ }, _obj),
1123
1122
  mode: glContext.LINES,
1124
1123
  indices: {
1125
1124
  data: index
@@ -2137,7 +2136,7 @@ var CameraGestureHandlerImp = /*#__PURE__*/ function() {
2137
2136
  registerPlugin("model", ModelPlugin);
2138
2137
  /**
2139
2138
  * 插件版本号
2140
- */ var version = "2.10.0-alpha.1";
2139
+ */ var version = "2.10.0-alpha.3";
2141
2140
  logger.info("Plugin model version: " + version + ".");
2142
2141
  if (version !== EFFECTS.version) {
2143
2142
  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!");
@@ -3404,30 +3403,27 @@ var normal = new Vector3();
3404
3403
  * @returns 几何参数
3405
3404
  */ MeshHelper.getPlaneGeometry = function getPlaneGeometry() {
3406
3405
  var data = MeshHelper.getPlaneVertexArray();
3406
+ var _obj;
3407
3407
  return {
3408
- attributes: {
3409
- aPos: {
3410
- type: glContext.FLOAT,
3411
- size: 3,
3412
- data: data,
3413
- stride: Float32Array.BYTES_PER_ELEMENT * 8,
3414
- offset: 0
3415
- },
3416
- aUV: {
3417
- type: glContext.FLOAT,
3418
- size: 2,
3419
- stride: Float32Array.BYTES_PER_ELEMENT * 8,
3420
- offset: Float32Array.BYTES_PER_ELEMENT * 3,
3421
- dataSource: "aPos"
3422
- },
3423
- aNormal: {
3424
- type: glContext.FLOAT,
3425
- size: 3,
3426
- stride: Float32Array.BYTES_PER_ELEMENT * 8,
3427
- offset: Float32Array.BYTES_PER_ELEMENT * 5,
3428
- dataSource: "aPos"
3429
- }
3430
- },
3408
+ attributes: (_obj = {}, _obj[VertexBuffer.PositionKind] = {
3409
+ type: glContext.FLOAT,
3410
+ size: 3,
3411
+ data: data,
3412
+ stride: Float32Array.BYTES_PER_ELEMENT * 8,
3413
+ offset: 0
3414
+ }, _obj[VertexBuffer.UVKind] = {
3415
+ type: glContext.FLOAT,
3416
+ size: 2,
3417
+ stride: Float32Array.BYTES_PER_ELEMENT * 8,
3418
+ offset: Float32Array.BYTES_PER_ELEMENT * 3,
3419
+ dataSource: VertexBuffer.PositionKind
3420
+ }, _obj[VertexBuffer.NormalKind] = {
3421
+ type: glContext.FLOAT,
3422
+ size: 3,
3423
+ stride: Float32Array.BYTES_PER_ELEMENT * 8,
3424
+ offset: Float32Array.BYTES_PER_ELEMENT * 5,
3425
+ dataSource: VertexBuffer.PositionKind
3426
+ }, _obj),
3431
3427
  drawStart: 0,
3432
3428
  drawCount: data.length / 8
3433
3429
  };
@@ -3854,19 +3850,19 @@ var normal = new Vector3();
3854
3850
  */ PluginHelper.getAttributeName = function getAttributeName(name) {
3855
3851
  switch(name){
3856
3852
  case "POSITION":
3857
- return "aPos";
3853
+ return VertexBuffer.PositionKind;
3858
3854
  case "NORMAL":
3859
- return "aNormal";
3855
+ return VertexBuffer.NormalKind;
3860
3856
  case "TANGENT":
3861
- return "aTangent";
3857
+ return VertexBuffer.TangentKind;
3862
3858
  case "TEXCOORD_0":
3863
- return "aUV";
3859
+ return VertexBuffer.UVKind;
3864
3860
  case "TEXCOORD_1":
3865
- return "aUV2";
3861
+ return VertexBuffer.UV2Kind;
3866
3862
  case "JOINTS_0":
3867
- return "aJoints";
3863
+ return VertexBuffer.JointsKind;
3868
3864
  case "WEIGHTS_0":
3869
- return "aWeights";
3865
+ return VertexBuffer.WeightsKind;
3870
3866
  }
3871
3867
  if (!name.startsWith("a")) {
3872
3868
  // aPos, aNormal, aTangent,
@@ -4217,21 +4213,18 @@ var AttributeArray = /*#__PURE__*/ function() {
4217
4213
  */ _proto.create = function create(geometry, bindMatrices) {
4218
4214
  this.drawStart = 0;
4219
4215
  this.drawCount = Math.abs(geometry.getDrawCount());
4220
- // FIXME: 需要geometry中的attributes数组,GLGeometry有这个数组,其他的没有
4221
- // @ts-expect-error
4222
- var attributes = geometry.attributes;
4223
4216
  //
4224
4217
  this.index = geometry.getIndexData();
4225
- var positionAttrib = attributes["aPos"];
4226
- var positionArray = geometry.getAttributeData("aPos");
4218
+ var positionAttrib = getAttributeLayout(geometry.getVertexBuffer(VertexBuffer.PositionKind));
4219
+ var positionArray = geometry.getAttributeData(VertexBuffer.PositionKind);
4227
4220
  this.position = new AttributeArray();
4228
4221
  this.position.create(positionAttrib, positionArray);
4229
4222
  //
4230
- var jointAttrib = attributes["aJoints"];
4231
- var weightAttrib = attributes["aWeights"];
4223
+ var jointAttrib = getAttributeLayout(geometry.getVertexBuffer(VertexBuffer.JointsKind));
4224
+ var weightAttrib = getAttributeLayout(geometry.getVertexBuffer(VertexBuffer.WeightsKind));
4232
4225
  if (jointAttrib !== undefined && weightAttrib !== undefined) {
4233
- var jointArray = geometry.getAttributeData("aJoints");
4234
- var weightArray = geometry.getAttributeData("aWeights");
4226
+ var jointArray = geometry.getAttributeData(VertexBuffer.JointsKind);
4227
+ var weightArray = geometry.getAttributeData(VertexBuffer.WeightsKind);
4235
4228
  this.joint = new AttributeArray();
4236
4229
  this.joint.create(jointAttrib, jointArray);
4237
4230
  this.weight = new AttributeArray();
@@ -4331,21 +4324,18 @@ var AttributeArray = /*#__PURE__*/ function() {
4331
4324
  */ _proto.create = function create(geometry, doubleSided, bindMatrices) {
4332
4325
  this.drawStart = 0;
4333
4326
  this.drawCount = Math.abs(geometry.getDrawCount());
4334
- // FIXME: 需要geometry中的attributes数组,GLGeometry有这个数组,其他的没有
4335
- // @ts-expect-error
4336
- var attributes = geometry.attributes;
4337
4327
  //
4338
4328
  this.index = geometry.getIndexData();
4339
- var positionAttrib = attributes["aPos"];
4340
- var positionArray = geometry.getAttributeData("aPos");
4329
+ var positionAttrib = getAttributeLayout(geometry.getVertexBuffer(VertexBuffer.PositionKind));
4330
+ var positionArray = geometry.getAttributeData(VertexBuffer.PositionKind);
4341
4331
  this.position = new AttributeArray();
4342
4332
  this.position.create(positionAttrib, positionArray);
4343
4333
  //
4344
- var jointAttrib = attributes["aJoints"];
4345
- var weightAttrib = attributes["aWeights"];
4334
+ var jointAttrib = getAttributeLayout(geometry.getVertexBuffer(VertexBuffer.JointsKind));
4335
+ var weightAttrib = getAttributeLayout(geometry.getVertexBuffer(VertexBuffer.WeightsKind));
4346
4336
  if (jointAttrib !== undefined && weightAttrib !== undefined) {
4347
- var jointArray = geometry.getAttributeData("aJoints");
4348
- var weightArray = geometry.getAttributeData("aWeights");
4337
+ var jointArray = geometry.getAttributeData(VertexBuffer.JointsKind);
4338
+ var weightArray = geometry.getAttributeData(VertexBuffer.WeightsKind);
4349
4339
  this.joint = new AttributeArray();
4350
4340
  this.joint.create(jointAttrib, jointArray);
4351
4341
  this.weight = new AttributeArray();
@@ -4427,6 +4417,18 @@ var AttributeArray = /*#__PURE__*/ function() {
4427
4417
  };
4428
4418
  return HitTestingProxy;
4429
4419
  }();
4420
+ function getAttributeLayout(vertexBuffer) {
4421
+ if (!vertexBuffer) {
4422
+ return;
4423
+ }
4424
+ return {
4425
+ type: vertexBuffer.type,
4426
+ size: vertexBuffer.getSize(),
4427
+ offset: vertexBuffer.byteOffset,
4428
+ stride: vertexBuffer.byteStride,
4429
+ normalize: vertexBuffer.normalized
4430
+ };
4431
+ }
4430
4432
  /**
4431
4433
  * 半精度浮点数组类
4432
4434
  */ var Float16ArrayWrapper = /*#__PURE__*/ function() {
@@ -6596,7 +6598,10 @@ var PSkyboxType;
6596
6598
  this.loadSkybox = loadSkybox;
6597
6599
  if (this.brdfLutTexture === undefined || this.brdfLutTexture.isDestroyed) {
6598
6600
  if (CompositionCache.brdfLutTexOptions === undefined) {
6599
- throw new Error("Please load brdfLutTexOptions at first.");
6601
+ // A Composition can be created and played directly without going through
6602
+ // the player's asynchronous asset-loading lifecycle. In that case the
6603
+ // optional BRDF LUT is not ready yet, but non-PBR content can still run.
6604
+ return;
6600
6605
  }
6601
6606
  //
6602
6607
  var brdfLutTextureName = "brdfLutTexture";
@@ -7230,6 +7235,14 @@ function _assert_this_initialized(self) {
7230
7235
  return self;
7231
7236
  }
7232
7237
 
7238
+ var uvKinds = [
7239
+ VertexBuffer.UVKind,
7240
+ VertexBuffer.UV2Kind,
7241
+ VertexBuffer.UV3Kind,
7242
+ VertexBuffer.UV4Kind,
7243
+ VertexBuffer.UV5Kind,
7244
+ VertexBuffer.UV6Kind
7245
+ ];
7233
7246
  /**
7234
7247
  * Mesh 类,负责 Mesh 相关的骨骼动画和 PBR 渲染
7235
7248
  */ var PMesh = /*#__PURE__*/ function(PEntity) {
@@ -8139,7 +8152,7 @@ function _assert_this_initialized(self) {
8139
8152
  * 是否压缩格式
8140
8153
  * @returns
8141
8154
  */ _proto.isCompressed = function isCompressed() {
8142
- var positionAttrib = this.geometry.getAttributeData("aPos");
8155
+ var positionAttrib = this.geometry.getAttributeData(VertexBuffer.PositionKind);
8143
8156
  if (positionAttrib === undefined) {
8144
8157
  return false;
8145
8158
  }
@@ -8151,48 +8164,45 @@ function _assert_this_initialized(self) {
8151
8164
  * 是否有位置属性
8152
8165
  * @returns
8153
8166
  */ _proto.hasPositions = function hasPositions() {
8154
- return this.hasAttribute("aPos");
8167
+ return this.hasAttribute(VertexBuffer.PositionKind);
8155
8168
  };
8156
8169
  /**
8157
8170
  * 是否有法线属性
8158
8171
  * @returns
8159
8172
  */ _proto.hasNormals = function hasNormals() {
8160
- return this.hasAttribute("aNormal");
8173
+ return this.hasAttribute(VertexBuffer.NormalKind);
8161
8174
  };
8162
8175
  /**
8163
8176
  * 是否有切线属性
8164
8177
  * @returns
8165
8178
  */ _proto.hasTangents = function hasTangents() {
8166
- return this.hasAttribute("aTangent");
8179
+ return this.hasAttribute(VertexBuffer.TangentKind);
8167
8180
  };
8168
8181
  /**
8169
8182
  * 是否有纹理坐标属性
8170
8183
  * @param index - 纹理坐标索引
8171
8184
  * @returns
8172
8185
  */ _proto.hasUVCoords = function hasUVCoords(index) {
8173
- if (index === 1) {
8174
- return this.hasAttribute("aUV");
8175
- } else {
8176
- return this.hasAttribute("aUV" + index);
8177
- }
8186
+ var kind = uvKinds[index - 1];
8187
+ return kind !== undefined && this.hasAttribute(kind);
8178
8188
  };
8179
8189
  /**
8180
8190
  * 是否有颜色属性
8181
8191
  * @returns
8182
8192
  */ _proto.hasColors = function hasColors() {
8183
- return this.hasAttribute("aColor");
8193
+ return this.hasAttribute(VertexBuffer.ColorKind);
8184
8194
  };
8185
8195
  /**
8186
8196
  * 是否有关节点属性
8187
8197
  * @returns
8188
8198
  */ _proto.hasJoints = function hasJoints() {
8189
- return this.hasAttribute("aJoints");
8199
+ return this.hasAttribute(VertexBuffer.JointsKind);
8190
8200
  };
8191
8201
  /**
8192
8202
  * 是否有权重属性
8193
8203
  * @returns
8194
8204
  */ _proto.hasWeights = function hasWeights() {
8195
- return this.hasAttribute("aWeights");
8205
+ return this.hasAttribute(VertexBuffer.WeightsKind);
8196
8206
  };
8197
8207
  return PGeometry;
8198
8208
  }();
@@ -8989,8 +8999,9 @@ var JSONConverter = /*#__PURE__*/ function() {
8989
8999
  var _geomProps_indices;
8990
9000
  var geomProps = deserializeGeometry(prim.geometry, oldScene.bins);
8991
9001
  var material = _this.getMaterialData(prim.material, oldScene);
8992
- if (_instanceof1((_geomProps_indices = geomProps.indices) == null ? void 0 : _geomProps_indices.data, Uint8Array)) {
8993
- var oldIndices = geomProps.indices.data;
9002
+ var indexData = (_geomProps_indices = geomProps.indices) == null ? void 0 : _geomProps_indices.data;
9003
+ if (_instanceof1(indexData, Uint8Array)) {
9004
+ var oldIndices = indexData;
8994
9005
  var newIndices = new Uint16Array(oldIndices.length);
8995
9006
  for(var i = 0; i < oldIndices.length; i++){
8996
9007
  newIndices[i] = oldIndices[i];
@@ -9647,7 +9658,7 @@ function getGeometryDataFromOptions(geomOptions) {
9647
9658
  verticesNormalize = (_attribData_normalize = attribData.normalize) != null ? _attribData_normalize : false;
9648
9659
  var _attribData_type;
9649
9660
  verticesType = glType2VertexFormatType((_attribData_type = attribData.type) != null ? _attribData_type : glContext.FLOAT);
9650
- } else if (attrib === "aNormal") {
9661
+ } else if (attrib === VertexBuffer.NormalKind) {
9651
9662
  // @ts-expect-error
9652
9663
  modelData.normals = attribData.data;
9653
9664
  var _attribData_normalize1;
@@ -9962,45 +9973,10 @@ function mergeTypedArray(array1, array2, offset) {
9962
9973
  return result6;
9963
9974
  }
9964
9975
  }
9965
- var vertexBufferSemanticMap = {
9966
- aPos: "POSITION",
9967
- aUV: "TEXCOORD0",
9968
- aUV2: "TEXCOORD1",
9969
- aNormal: "NORMAL",
9970
- aTangent: "TANGENT",
9971
- aColor: "COLOR",
9972
- aJoints: "JOINTS",
9973
- aWeights: "WEIGHTS",
9974
- //
9975
- a_Position: "POSITION",
9976
- a_UV: "TEXCOORD0",
9977
- a_UV1: "TEXCOORD0",
9978
- a_UV2: "TEXCOORD1",
9979
- a_Normal: "NORMAL",
9980
- a_Tangent: "TANGENT",
9981
- a_Color: "COLOR",
9982
- a_Joints: "JOINTS",
9983
- a_Joint1: "JOINTS",
9984
- a_Weights: "WEIGHTS",
9985
- a_Weight1: "WEIGHTS",
9986
- //
9987
- a_Target_Position0: "POSITION_BS0",
9988
- a_Target_Position1: "POSITION_BS1",
9989
- a_Target_Position2: "POSITION_BS2",
9990
- a_Target_Position3: "POSITION_BS3",
9991
- a_Target_Position4: "POSITION_BS4",
9992
- a_Target_Position5: "POSITION_BS5",
9993
- a_Target_Position6: "POSITION_BS6",
9994
- a_Target_Position7: "POSITION_BS7",
9995
- a_Target_Normal0: "NORMAL_BS0",
9996
- a_Target_Normal1: "NORMAL_BS1",
9997
- a_Target_Normal2: "NORMAL_BS2",
9998
- a_Target_Normal3: "NORMAL_BS3",
9999
- a_Target_Tangent0: "TANGENT_BS0",
10000
- a_Target_Tangent1: "TANGENT_BS1",
10001
- a_Target_Tangent2: "TANGENT_BS2",
10002
- a_Target_Tangent3: "TANGENT_BS3"
10003
- };
9976
+ var _obj;
9977
+ var vertexBufferSemanticMap = (_obj = {}, _obj[VertexBuffer.PositionKind] = "POSITION", _obj[VertexBuffer.UVKind] = "TEXCOORD0", _obj[VertexBuffer.UV2Kind] = "TEXCOORD1", _obj[VertexBuffer.NormalKind] = "NORMAL", _obj[VertexBuffer.TangentKind] = "TANGENT", _obj[VertexBuffer.ColorKind] = "COLOR", _obj[VertexBuffer.JointsKind] = "JOINTS", _obj[VertexBuffer.WeightsKind] = "WEIGHTS", //
9978
+ _obj.a_Position = "POSITION", _obj.a_UV = "TEXCOORD0", _obj.a_UV1 = "TEXCOORD0", _obj.a_UV2 = "TEXCOORD1", _obj.a_Normal = "NORMAL", _obj.a_Tangent = "TANGENT", _obj.a_Color = "COLOR", _obj.a_Joints = "JOINTS", _obj.a_Joint1 = "JOINTS", _obj.a_Weights = "WEIGHTS", _obj.a_Weight1 = "WEIGHTS", //
9979
+ _obj.a_Target_Position0 = "POSITION_BS0", _obj.a_Target_Position1 = "POSITION_BS1", _obj.a_Target_Position2 = "POSITION_BS2", _obj.a_Target_Position3 = "POSITION_BS3", _obj.a_Target_Position4 = "POSITION_BS4", _obj.a_Target_Position5 = "POSITION_BS5", _obj.a_Target_Position6 = "POSITION_BS6", _obj.a_Target_Position7 = "POSITION_BS7", _obj.a_Target_Normal0 = "NORMAL_BS0", _obj.a_Target_Normal1 = "NORMAL_BS1", _obj.a_Target_Normal2 = "NORMAL_BS2", _obj.a_Target_Normal3 = "NORMAL_BS3", _obj.a_Target_Tangent0 = "TANGENT_BS0", _obj.a_Target_Tangent1 = "TANGENT_BS1", _obj.a_Target_Tangent2 = "TANGENT_BS2", _obj.a_Target_Tangent3 = "TANGENT_BS3", _obj);
10004
9980
 
10005
9981
  function getDefaultEffectsGLTFLoader(engine, options) {
10006
9982
  if (!defaultGLTFLoader) {
@@ -10885,8 +10861,8 @@ var LoaderImpl = /*#__PURE__*/ function() {
10885
10861
  return false;
10886
10862
  }
10887
10863
  };
10888
- /**
10889
- * for old scene compatibility
10864
+ /**
10865
+ * for old scene compatibility
10890
10866
  */ _proto.processLight = function processLight(lights, fromGLTF) {
10891
10867
  var _this = this;
10892
10868
  lights.forEach(function(l) {
@@ -11260,8 +11236,8 @@ var GeometryProxy = /*#__PURE__*/ function() {
11260
11236
  attributes["a_Weight1"] = this._getBufferAttrib(weightAttrib);
11261
11237
  }
11262
11238
  }
11263
- /**
11264
- * 设置Morph动画需要的Attribute,主要包括Position,Normal和Tangent
11239
+ /**
11240
+ * 设置Morph动画需要的Attribute,主要包括Position,Normal和Tangent
11265
11241
  */ for(var i = 0; i < 8; i++){
11266
11242
  var positionAttrib = this.getTargetPosition(i);
11267
11243
  if (positionAttrib !== undefined) {
@@ -11278,13 +11254,14 @@ var GeometryProxy = /*#__PURE__*/ function() {
11278
11254
  }
11279
11255
  var indexArray = this.indexArray;
11280
11256
  if (indexArray !== undefined) {
11257
+ var indices = _instanceof1(indexArray, Uint8Array) ? new Uint16Array(indexArray) : indexArray;
11281
11258
  return Geometry.create(this.engine, {
11282
11259
  attributes: attributes,
11283
11260
  indices: {
11284
- data: indexArray
11261
+ data: indices
11285
11262
  },
11286
11263
  drawStart: 0,
11287
- drawCount: indexArray.length,
11264
+ drawCount: indices.length,
11288
11265
  mode: glContext.TRIANGLES
11289
11266
  });
11290
11267
  } else {