@galacean/engine-loader 1.0.0-beta.17 → 1.0.0-beta.19

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/main.js CHANGED
@@ -40,56 +40,61 @@ function _inherits(subClass, superClass) {
40
40
  if (superClass) _set_prototype_of(subClass, superClass);
41
41
  }
42
42
 
43
- /******************************************************************************
44
- Copyright (c) Microsoft Corporation.
45
-
46
- Permission to use, copy, modify, and/or distribute this software for any
47
- purpose with or without fee is hereby granted.
48
-
49
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
50
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
51
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
52
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
53
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
54
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
55
- PERFORMANCE OF THIS SOFTWARE.
56
- ***************************************************************************** */
57
-
58
- function __decorate(decorators, target, key, desc) {
59
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
60
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
61
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
62
- return c > 3 && r && Object.defineProperty(target, key, r), r;
63
- }
64
-
65
- function __generator(thisArg, body) {
66
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
67
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
68
- function verb(n) { return function (v) { return step([n, v]); }; }
69
- function step(op) {
70
- if (f) throw new TypeError("Generator is already executing.");
71
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
72
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
73
- if (y = 0, t) op = [op[0] & 2, t.value];
74
- switch (op[0]) {
75
- case 0: case 1: t = op; break;
76
- case 4: _.label++; return { value: op[1], done: false };
77
- case 5: _.label++; y = op[1]; op = [0]; continue;
78
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
79
- default:
80
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
81
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
82
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
83
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
84
- if (t[2]) _.ops.pop();
85
- _.trys.pop(); continue;
86
- }
87
- op = body.call(thisArg, _);
88
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
89
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
90
- }
43
+ /******************************************************************************
44
+ Copyright (c) Microsoft Corporation.
45
+
46
+ Permission to use, copy, modify, and/or distribute this software for any
47
+ purpose with or without fee is hereby granted.
48
+
49
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
50
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
51
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
52
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
53
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
54
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
55
+ PERFORMANCE OF THIS SOFTWARE.
56
+ ***************************************************************************** */
57
+
58
+ function __decorate(decorators, target, key, desc) {
59
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
60
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
61
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
62
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
63
+ }
64
+
65
+ function __generator(thisArg, body) {
66
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
67
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
68
+ function verb(n) { return function (v) { return step([n, v]); }; }
69
+ function step(op) {
70
+ if (f) throw new TypeError("Generator is already executing.");
71
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
72
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
73
+ if (y = 0, t) op = [op[0] & 2, t.value];
74
+ switch (op[0]) {
75
+ case 0: case 1: t = op; break;
76
+ case 4: _.label++; return { value: op[1], done: false };
77
+ case 5: _.label++; y = op[1]; op = [0]; continue;
78
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
79
+ default:
80
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
81
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
82
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
83
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
84
+ if (t[2]) _.ops.pop();
85
+ _.trys.pop(); continue;
86
+ }
87
+ op = body.call(thisArg, _);
88
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
89
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
90
+ }
91
91
  }
92
92
 
93
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
94
+ var e = new Error(message);
95
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
96
+ };
97
+
93
98
  var AnimatorControllerLoader = /*#__PURE__*/ function(Loader1) {
94
99
  _inherits(AnimatorControllerLoader, Loader1);
95
100
  function AnimatorControllerLoader() {
@@ -443,15 +448,18 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
443
448
  for(var _iterator2 = _create_for_of_iterator_helper_loose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
444
449
  var restoreInfo = _step2.value;
445
450
  var frame = restoreInfo.blendShape.frames[0];
446
- var positionData = _this._getBufferData(buffers, restoreInfo.position);
447
- frame.deltaPositions = GLTFUtils.floatBufferToVector3Array(positionData);
451
+ var position = restoreInfo.position;
452
+ var positionData = _this._getBufferData(buffers, position.buffer);
453
+ frame.deltaPositions = GLTFUtils.bufferToVector3Array(positionData, position.stride, position.byteOffset, position.count);
448
454
  if (restoreInfo.normal) {
449
- var normalData = _this._getBufferData(buffers, restoreInfo.normal);
450
- frame.deltaNormals = GLTFUtils.floatBufferToVector3Array(normalData);
455
+ var normal = restoreInfo.normal;
456
+ var normalData = _this._getBufferData(buffers, normal.buffer);
457
+ frame.deltaNormals = GLTFUtils.bufferToVector3Array(normalData, normal.stride, normal.byteOffset, normal.count);
451
458
  }
452
459
  if (restoreInfo.tangent) {
453
- var tangentData = _this._getBufferData(buffers, restoreInfo.tangent);
454
- frame.deltaTangents = GLTFUtils.floatBufferToVector3Array(tangentData);
460
+ var tangent = restoreInfo.tangent;
461
+ var tangentData = _this._getBufferData(buffers, tangent.buffer);
462
+ frame.deltaTangents = GLTFUtils.bufferToVector3Array(tangentData, tangent.stride, tangent.byteOffset, tangent.count);
455
463
  }
456
464
  }
457
465
  mesh.uploadData(true);
@@ -535,6 +543,14 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
535
543
  this.normal = normal;
536
544
  this.tangent = tangent;
537
545
  };
546
+ /**
547
+ * @internal
548
+ */ var BlendShapeDataRestoreInfo = function BlendShapeDataRestoreInfo(buffer, stride, byteOffset, count) {
549
+ this.buffer = buffer;
550
+ this.stride = stride;
551
+ this.byteOffset = byteOffset;
552
+ this.count = count;
553
+ };
538
554
 
539
555
  /**
540
556
  * Module for glTF 2.0 Interface
@@ -837,8 +853,10 @@ var TextureWrapMode;
837
853
  return context.getBuffers().then(function(buffers) {
838
854
  var bufferIndex = bufferView.buffer;
839
855
  var buffer = buffers[bufferIndex];
840
- var bufferByteOffset = bufferView.byteOffset || 0;
841
- var byteOffset = accessor.byteOffset || 0;
856
+ var _bufferView_byteOffset;
857
+ var bufferByteOffset = (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0;
858
+ var _accessor_byteOffset;
859
+ var byteOffset = (_accessor_byteOffset = accessor.byteOffset) != null ? _accessor_byteOffset : 0;
842
860
  var TypedArray = GLTFUtils.getComponentType(componentType);
843
861
  var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
844
862
  var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
@@ -872,6 +890,17 @@ var TextureWrapMode;
872
890
  return bufferInfo;
873
891
  });
874
892
  };
893
+ GLTFUtils.bufferToVector3Array = function bufferToVector3Array(data, byteStride, accessorByteOffset, count) {
894
+ var bytesPerElement = data.BYTES_PER_ELEMENT;
895
+ var offset = accessorByteOffset % byteStride / bytesPerElement;
896
+ var stride = byteStride / bytesPerElement;
897
+ var vector3s = new Array(count);
898
+ for(var i = 0; i < count; i++){
899
+ var index = offset + i * stride;
900
+ vector3s[i] = new engineMath.Vector3(data[index], data[index + 1], data[index + 2]);
901
+ }
902
+ return vector3s;
903
+ };
875
904
  /**
876
905
  * @deprecated
877
906
  * Get accessor data.
@@ -1975,7 +2004,7 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1975
2004
  }
1976
2005
  // BlendShapes
1977
2006
  if (targets) {
1978
- promises.push(GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData));
2007
+ promises.push(GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, accessors, targets, getBlendShapeData));
1979
2008
  }
1980
2009
  return Promise.all(promises).then(function() {
1981
2010
  mesh.uploadData(!keepMeshData);
@@ -1991,7 +2020,7 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1991
2020
  };
1992
2021
  /**
1993
2022
  * @internal
1994
- */ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
2023
+ */ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, accessors, glTFTargets, getBlendShapeData) {
1995
2024
  var _loop = function(i, n) {
1996
2025
  var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
1997
2026
  var promise = Promise.all([
@@ -1999,16 +2028,36 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
1999
2028
  getBlendShapeData("NORMAL", i),
2000
2029
  getBlendShapeData("TANGENT", i)
2001
2030
  ]).then(function(infos) {
2002
- var deltaPosBufferInfo = infos[0];
2003
- var deltaNorBufferInfo = infos[1];
2004
- var deltaTanBufferInfo = infos[2];
2005
- var deltaPositions = deltaPosBufferInfo.data ? GLTFUtils.floatBufferToVector3Array(deltaPosBufferInfo.data) : null;
2006
- var deltaNormals = (deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) : null;
2007
- var deltaTangents = (deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) : null;
2031
+ var posBufferInfo = infos[0];
2032
+ var norBufferInfo = infos[1];
2033
+ var tanBufferInfo = infos[2];
2034
+ var target = glTFTargets[i];
2035
+ var posAccessor;
2036
+ var norAccessor;
2037
+ var tanAccessor;
2038
+ var positions = null;
2039
+ if (posBufferInfo) {
2040
+ posAccessor = accessors[target["POSITION"]];
2041
+ var _posAccessor_byteOffset;
2042
+ positions = GLTFUtils.bufferToVector3Array(posBufferInfo.data, posBufferInfo.stride, (_posAccessor_byteOffset = posAccessor.byteOffset) != null ? _posAccessor_byteOffset : 0, posAccessor.count);
2043
+ }
2044
+ var normals = null;
2045
+ if (norBufferInfo) {
2046
+ norAccessor = accessors[target["NORMAL"]];
2047
+ var _norAccessor_byteOffset;
2048
+ normals = GLTFUtils.bufferToVector3Array(norBufferInfo.data, norBufferInfo.stride, (_norAccessor_byteOffset = norAccessor.byteOffset) != null ? _norAccessor_byteOffset : 0, norAccessor.count);
2049
+ }
2050
+ var tangents = null;
2051
+ if (tanBufferInfo) {
2052
+ tanAccessor = accessors[target["NORMAL"]];
2053
+ var _tanAccessor_byteOffset;
2054
+ tangents = GLTFUtils.bufferToVector3Array(tanBufferInfo.data, tanBufferInfo.stride, (_tanAccessor_byteOffset = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset : 0, tanAccessor.count);
2055
+ }
2008
2056
  var blendShape = new engineCore.BlendShape(name);
2009
- blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
2057
+ blendShape.addFrame(1.0, positions, normals, tangents);
2010
2058
  mesh.addBlendShape(blendShape);
2011
- meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, deltaPosBufferInfo.restoreInfo, deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.restoreInfo, deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.restoreInfo));
2059
+ var _posAccessor_byteOffset1, _norAccessor_byteOffset1, _tanAccessor_byteOffset1;
2060
+ meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, new BlendShapeDataRestoreInfo(posBufferInfo.restoreInfo, posBufferInfo.stride, (_posAccessor_byteOffset1 = posAccessor.byteOffset) != null ? _posAccessor_byteOffset1 : 0, posAccessor.count), norBufferInfo ? new BlendShapeDataRestoreInfo(norBufferInfo.restoreInfo, norBufferInfo.stride, (_norAccessor_byteOffset1 = norAccessor.byteOffset) != null ? _norAccessor_byteOffset1 : 0, norAccessor.count) : null, tanBufferInfo ? new BlendShapeDataRestoreInfo(tanBufferInfo.restoreInfo, tanBufferInfo.stride, (_tanAccessor_byteOffset1 = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset1 : 0, tanAccessor.count) : null));
2012
2061
  });
2013
2062
  promises.push(promise);
2014
2063
  };
@@ -2338,13 +2387,13 @@ var GLTFTextureParser = /*#__PURE__*/ function(GLTFParser) {
2338
2387
  };
2339
2388
  _proto._parseSampler = function _parseSampler(texture, samplerInfo) {
2340
2389
  var filterMode = samplerInfo.filterMode, wrapModeU = samplerInfo.wrapModeU, wrapModeV = samplerInfo.wrapModeV;
2341
- if (filterMode) {
2390
+ if (filterMode !== undefined) {
2342
2391
  texture.filterMode = filterMode;
2343
2392
  }
2344
- if (wrapModeU) {
2393
+ if (wrapModeU !== undefined) {
2345
2394
  texture.wrapModeU = wrapModeU;
2346
2395
  }
2347
- if (wrapModeV) {
2396
+ if (wrapModeV !== undefined) {
2348
2397
  texture.wrapModeV = wrapModeV;
2349
2398
  }
2350
2399
  };
@@ -2482,7 +2531,7 @@ var GLTFLoader = /*#__PURE__*/ function(Loader) {
2482
2531
  resourceManager.addContentRestorer(restorer);
2483
2532
  masterPromiseInfo.resolve(glTFResource);
2484
2533
  }).catch(function(e) {
2485
- var msg = "Error loading glTF model from " + url + " .";
2534
+ var msg = "Error loading glTF model from " + url + " : " + e;
2486
2535
  engineCore.Logger.error(msg);
2487
2536
  masterPromiseInfo.reject(msg);
2488
2537
  context.defaultSceneRootPromiseInfo.reject(e);
@@ -4720,7 +4769,7 @@ var KHR_draco_mesh_compression = (_KHR_draco_mesh_compression = /*#__PURE__*/ fu
4720
4769
  mesh.addSubMesh(0, vertexCount, mode);
4721
4770
  }
4722
4771
  // BlendShapes
4723
- targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, targets, getBlendShapeData);
4772
+ targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, accessors, targets, getBlendShapeData);
4724
4773
  mesh.uploadData(!keepMeshData);
4725
4774
  return Promise.resolve(mesh);
4726
4775
  };