@galacean/engine-loader 1.1.0-beta.46 → 1.1.0-beta.47

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
@@ -2060,7 +2060,7 @@ function registerGLTFParser(pipeline) {
2060
2060
  };
2061
2061
  /**
2062
2062
  * Parse the glb format.
2063
- */ GLTFUtils.parseGLB = function parseGLB(context, glb) {
2063
+ */ GLTFUtils.parseGLB = function parseGLB(context, originBuffer) {
2064
2064
  var UINT32_LENGTH = 4;
2065
2065
  var GLB_HEADER_MAGIC = 0x46546c67; // 'glTF'
2066
2066
  var GLB_HEADER_LENGTH = 12;
@@ -2068,7 +2068,7 @@ function registerGLTFParser(pipeline) {
2068
2068
  JSON: 0x4e4f534a,
2069
2069
  BIN: 0x004e4942
2070
2070
  };
2071
- var dataView = new DataView(glb);
2071
+ var dataView = new DataView(originBuffer);
2072
2072
  // read header
2073
2073
  var header = {
2074
2074
  magic: dataView.getUint32(0, true),
@@ -2076,8 +2076,9 @@ function registerGLTFParser(pipeline) {
2076
2076
  length: dataView.getUint32(2 * UINT32_LENGTH, true)
2077
2077
  };
2078
2078
  if (header.magic !== GLB_HEADER_MAGIC) {
2079
- console.error("Invalid glb magic number. Expected 0x46546C67, found 0x" + header.magic.toString(16));
2080
- return null;
2079
+ return {
2080
+ originBuffer: originBuffer
2081
+ };
2081
2082
  }
2082
2083
  // read main data
2083
2084
  var chunkLength = dataView.getUint32(GLB_HEADER_LENGTH, true);
@@ -2087,7 +2088,7 @@ function registerGLTFParser(pipeline) {
2087
2088
  console.error("Invalid glb chunk type. Expected 0x4E4F534A, found 0x" + chunkType.toString(16));
2088
2089
  return null;
2089
2090
  }
2090
- var glTFData = new Uint8Array(glb, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
2091
+ var glTFData = new Uint8Array(originBuffer, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength);
2091
2092
  var glTF = JSON.parse(engineCore.Utils.decodeText(glTFData));
2092
2093
  // read all buffers
2093
2094
  var buffers = [];
@@ -2101,7 +2102,7 @@ function registerGLTFParser(pipeline) {
2101
2102
  return null;
2102
2103
  }
2103
2104
  var currentOffset = byteOffset + 2 * UINT32_LENGTH;
2104
- var buffer = glb.slice(currentOffset, currentOffset + chunkLength);
2105
+ var buffer = originBuffer.slice(currentOffset, currentOffset + chunkLength);
2105
2106
  buffers.push(buffer);
2106
2107
  restoreGLBBufferSlice.push(new engineMath.Vector2(currentOffset, chunkLength));
2107
2108
  byteOffset += chunkLength + 2 * UINT32_LENGTH;
@@ -3511,23 +3512,20 @@ exports.GLTFSchemaParser = /*#__PURE__*/ function(GLTFParser1) {
3511
3512
  var requestConfig = {
3512
3513
  type: "arraybuffer"
3513
3514
  };
3514
- var isGLB = this._isGLB(url);
3515
- contentRestorer.isGLB = isGLB;
3516
- var promise = isGLB ? engineCore.request(url, requestConfig).then(function(glb) {
3515
+ return engineCore.request(url, requestConfig).then(function(buffer) {
3517
3516
  restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig));
3518
- return GLTFUtils.parseGLB(context, glb);
3519
- }).then(function(param) {
3520
- var glTF = param.glTF, buffers = param.buffers;
3521
- context.buffers = buffers;
3522
- return glTF;
3523
- }) : engineCore.request(url, {
3524
- type: "json"
3517
+ return GLTFUtils.parseGLB(context, buffer);
3518
+ }).then(function(result) {
3519
+ var _result;
3520
+ if ((_result = result) == null ? void 0 : _result.glTF) {
3521
+ contentRestorer.isGLB = true;
3522
+ context.buffers = result.buffers;
3523
+ return result.glTF;
3524
+ } else {
3525
+ contentRestorer.isGLB = false;
3526
+ return JSON.parse(engineCore.Utils.decodeText(new Uint8Array(result.originBuffer)));
3527
+ }
3525
3528
  });
3526
- return promise;
3527
- };
3528
- _proto._isGLB = function _isGLB(url) {
3529
- var index = url.lastIndexOf(".");
3530
- return url.substring(index + 1, index + 4) === "glb";
3531
3529
  };
3532
3530
  return GLTFSchemaParser;
3533
3531
  }(GLTFParser);