@galacean/engine 1.0.0-beta.16 → 1.0.0-beta.18

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/browser.js CHANGED
@@ -6483,6 +6483,11 @@
6483
6483
  subFont.nativeFontString = fontString;
6484
6484
  for(var i = 0, n = subTexts.length; i < n; i++){
6485
6485
  var subText = subTexts[i];
6486
+ // If subText is empty, push an empty line directly
6487
+ if (subText.length === 0) {
6488
+ this._pushLine(lines, lineWidths, lineMaxSizes, "", 0, 0, 0);
6489
+ continue;
6490
+ }
6486
6491
  var word = "";
6487
6492
  var wordWidth = 0;
6488
6493
  var wordMaxAscent = 0;
@@ -6510,7 +6515,10 @@
6510
6515
  // If it is a word before, need to handle the previous word and line
6511
6516
  if (word.length > 0) {
6512
6517
  if (lineWidth + wordWidth > wrapWidth) {
6513
- this._pushLine(lines, lineWidths, lineMaxSizes, line, lineWidth, lineMaxAscent, lineMaxDescent);
6518
+ // Push if before line is not empty
6519
+ if (lineWidth > 0) {
6520
+ this._pushLine(lines, lineWidths, lineMaxSizes, line, lineWidth, lineMaxAscent, lineMaxDescent);
6521
+ }
6514
6522
  textWidth = Math.max(textWidth, lineWidth);
6515
6523
  notFirstLine = true;
6516
6524
  line = word;
@@ -6555,7 +6563,10 @@
6555
6563
  line = "";
6556
6564
  lineWidth = lineMaxAscent = lineMaxDescent = 0;
6557
6565
  }
6558
- this._pushLine(lines, lineWidths, lineMaxSizes, word, wordWidth, wordMaxAscent, wordMaxDescent);
6566
+ // Push if before word is not empty
6567
+ if (wordWidth > 0) {
6568
+ this._pushLine(lines, lineWidths, lineMaxSizes, word, wordWidth, wordMaxAscent, wordMaxDescent);
6569
+ }
6559
6570
  textWidth = Math.max(textWidth, wordWidth);
6560
6571
  notFirstLine = true;
6561
6572
  word = char;
@@ -6574,11 +6585,15 @@
6574
6585
  // If the total width from line and word exceed wrap width
6575
6586
  if (lineWidth + wordWidth > wrapWidth) {
6576
6587
  // Push chars to a single line
6577
- this._pushLine(lines, lineWidths, lineMaxSizes, line, lineWidth, lineMaxAscent, lineMaxDescent);
6588
+ if (lineWidth > 0) {
6589
+ this._pushLine(lines, lineWidths, lineMaxSizes, line, lineWidth, lineMaxAscent, lineMaxDescent);
6590
+ }
6578
6591
  textWidth = Math.max(textWidth, lineWidth);
6579
6592
  lineWidth = 0;
6580
6593
  // Push word to a single line
6581
- this._pushLine(lines, lineWidths, lineMaxSizes, word, wordWidth, wordMaxAscent, wordMaxDescent);
6594
+ if (wordWidth > 0) {
6595
+ this._pushLine(lines, lineWidths, lineMaxSizes, word, wordWidth, wordMaxAscent, wordMaxDescent);
6596
+ }
6582
6597
  textWidth = Math.max(textWidth, wordWidth);
6583
6598
  } else {
6584
6599
  // Merge to chars
@@ -6610,23 +6625,20 @@
6610
6625
  var subFont = renderer._subFont;
6611
6626
  var fontString = subFont.nativeFontString;
6612
6627
  var fontSizeInfo = TextUtils.measureFont(fontString);
6613
- var lines = renderer.text.split(/(?:\r\n|\r|\n)/);
6614
- var lineCount = lines.length;
6628
+ var subTexts = renderer.text.split(/(?:\r\n|\r|\n)/);
6629
+ var textCount = subTexts.length;
6630
+ var lines = new Array();
6615
6631
  var lineWidths = new Array();
6616
6632
  var lineMaxSizes = new Array();
6617
6633
  var _pixelsPerUnit = Engine._pixelsPerUnit;
6618
6634
  var lineHeight = fontSizeInfo.size + renderer.lineSpacing * _pixelsPerUnit;
6619
6635
  var width = 0;
6620
- var height = renderer.height * _pixelsPerUnit;
6621
- if (renderer.overflowMode === exports.OverflowMode.Overflow) {
6622
- height = lineHeight * lineCount;
6623
- }
6624
6636
  subFont.nativeFontString = fontString;
6625
- for(var i = 0; i < lineCount; ++i){
6626
- var line = lines[i];
6637
+ for(var i = 0; i < textCount; ++i){
6638
+ var line = subTexts[i];
6627
6639
  var curWidth = 0;
6628
- var maxAscent = -1;
6629
- var maxDescent = -1;
6640
+ var maxAscent = 0;
6641
+ var maxDescent = 0;
6630
6642
  for(var j = 0, m = line.length; j < m; ++j){
6631
6643
  var charInfo = TextUtils._getCharInfo(line[j], fontString, subFont);
6632
6644
  curWidth += charInfo.xAdvance;
@@ -6637,16 +6649,15 @@
6637
6649
  maxAscent < ascent && (maxAscent = ascent);
6638
6650
  maxDescent < descent && (maxDescent = descent);
6639
6651
  }
6640
- lineWidths[i] = curWidth;
6641
- lineMaxSizes[i] = {
6642
- ascent: maxAscent,
6643
- descent: maxDescent,
6644
- size: maxAscent + maxDescent
6645
- };
6646
- if (curWidth > width) {
6647
- width = curWidth;
6652
+ if (curWidth > 0) {
6653
+ this._pushLine(lines, lineWidths, lineMaxSizes, line, curWidth, maxAscent, maxDescent);
6654
+ width = Math.max(width, curWidth);
6648
6655
  }
6649
6656
  }
6657
+ var height = renderer.height * _pixelsPerUnit;
6658
+ if (renderer.overflowMode === exports.OverflowMode.Overflow) {
6659
+ height = lineHeight * lines.length;
6660
+ }
6650
6661
  return {
6651
6662
  width: width,
6652
6663
  height: height,
@@ -7492,7 +7503,6 @@
7492
7503
  var EventDispatcher = function EventDispatcher() {
7493
7504
  this._events = Object.create(null);
7494
7505
  this._eventCount = 0;
7495
- this._dispatchingListeners = [];
7496
7506
  };
7497
7507
  var _proto = EventDispatcher.prototype;
7498
7508
  /**
@@ -7532,7 +7542,8 @@
7532
7542
  if (Array.isArray(listeners)) {
7533
7543
  var count = listeners.length;
7534
7544
  // cloning list to avoid structure breaking
7535
- var dispatchingListeners = this._dispatchingListeners;
7545
+ var pool = EventDispatcher._dispatchingListenersPool;
7546
+ var dispatchingListeners = pool.length > 0 ? pool.pop() : [];
7536
7547
  dispatchingListeners.length = count;
7537
7548
  for(var i = 0; i < count; i++){
7538
7549
  dispatchingListeners[i] = listeners[i];
@@ -7546,6 +7557,7 @@
7546
7557
  }
7547
7558
  // remove hooked function to avoid gc problem
7548
7559
  dispatchingListeners.length = 0;
7560
+ pool.push(dispatchingListeners);
7549
7561
  } else {
7550
7562
  if (listeners.once) this.off(event, listeners.fn);
7551
7563
  listeners.fn(data);
@@ -7646,6 +7658,9 @@
7646
7658
  };
7647
7659
  return EventDispatcher;
7648
7660
  }();
7661
+ (function() {
7662
+ EventDispatcher._dispatchingListenersPool = [];
7663
+ })();
7649
7664
  /**
7650
7665
  * Shader property.
7651
7666
  */ var ShaderProperty = /*#__PURE__*/ function() {
@@ -9628,6 +9643,7 @@
9628
9643
  cloneEntity._hookResource = hookResource;
9629
9644
  hookResource._addReferCount(1);
9630
9645
  }
9646
+ cloneEntity.layer = this.layer;
9631
9647
  cloneEntity._isActive = this._isActive;
9632
9648
  cloneEntity.transform.localMatrix = this.transform.localMatrix;
9633
9649
  var children = this._children;
@@ -18428,6 +18444,15 @@
18428
18444
  };
18429
18445
  /**
18430
18446
  * @internal
18447
+ */ _proto._prepareRender = function _prepareRender(context) {
18448
+ if (!this._mesh) {
18449
+ Logger.error("mesh is null.");
18450
+ return;
18451
+ }
18452
+ Renderer.prototype._prepareRender.call(this, context);
18453
+ };
18454
+ /**
18455
+ * @internal
18431
18456
  */ _proto._cloneTo = function _cloneTo(target) {
18432
18457
  Renderer.prototype._cloneTo.call(this, target);
18433
18458
  target.mesh = this._mesh;
@@ -18449,49 +18474,45 @@
18449
18474
  * @internal
18450
18475
  */ _proto._render = function _render(context) {
18451
18476
  var mesh = this._mesh;
18452
- if (mesh) {
18453
- if (this._dirtyUpdateFlag & 0x2) {
18454
- var shaderData = this.shaderData;
18455
- var vertexElements = mesh._vertexElements;
18456
- shaderData.disableMacro(MeshRenderer._uvMacro);
18457
- shaderData.disableMacro(MeshRenderer._uv1Macro);
18458
- shaderData.disableMacro(MeshRenderer._normalMacro);
18459
- shaderData.disableMacro(MeshRenderer._tangentMacro);
18460
- shaderData.disableMacro(MeshRenderer._enableVertexColorMacro);
18461
- for(var i = 0, n = vertexElements.length; i < n; i++){
18462
- switch(vertexElements[i].semantic){
18463
- case "TEXCOORD_0":
18464
- shaderData.enableMacro(MeshRenderer._uvMacro);
18465
- break;
18466
- case "TEXCOORD_1":
18467
- shaderData.enableMacro(MeshRenderer._uv1Macro);
18468
- break;
18469
- case "NORMAL":
18470
- shaderData.enableMacro(MeshRenderer._normalMacro);
18471
- break;
18472
- case "TANGENT":
18473
- shaderData.enableMacro(MeshRenderer._tangentMacro);
18474
- break;
18475
- case "COLOR_0":
18476
- this._enableVertexColor && shaderData.enableMacro(MeshRenderer._enableVertexColorMacro);
18477
- break;
18478
- }
18477
+ if (this._dirtyUpdateFlag & 0x2) {
18478
+ var shaderData = this.shaderData;
18479
+ var vertexElements = mesh._vertexElements;
18480
+ shaderData.disableMacro(MeshRenderer._uvMacro);
18481
+ shaderData.disableMacro(MeshRenderer._uv1Macro);
18482
+ shaderData.disableMacro(MeshRenderer._normalMacro);
18483
+ shaderData.disableMacro(MeshRenderer._tangentMacro);
18484
+ shaderData.disableMacro(MeshRenderer._enableVertexColorMacro);
18485
+ for(var i = 0, n = vertexElements.length; i < n; i++){
18486
+ switch(vertexElements[i].semantic){
18487
+ case "TEXCOORD_0":
18488
+ shaderData.enableMacro(MeshRenderer._uvMacro);
18489
+ break;
18490
+ case "TEXCOORD_1":
18491
+ shaderData.enableMacro(MeshRenderer._uv1Macro);
18492
+ break;
18493
+ case "NORMAL":
18494
+ shaderData.enableMacro(MeshRenderer._normalMacro);
18495
+ break;
18496
+ case "TANGENT":
18497
+ shaderData.enableMacro(MeshRenderer._tangentMacro);
18498
+ break;
18499
+ case "COLOR_0":
18500
+ this._enableVertexColor && shaderData.enableMacro(MeshRenderer._enableVertexColorMacro);
18501
+ break;
18479
18502
  }
18480
- this._dirtyUpdateFlag &= ~0x2;
18481
18503
  }
18482
- var materials = this._materials;
18483
- var subMeshes = mesh.subMeshes;
18484
- var renderPipeline = context.camera._renderPipeline;
18485
- var meshRenderDataPool = this._engine._meshRenderDataPool;
18486
- for(var i1 = 0, n1 = subMeshes.length; i1 < n1; i1++){
18487
- var material = materials[i1];
18488
- if (!material) continue;
18489
- var renderData = meshRenderDataPool.getFromPool();
18490
- renderData.set(this, material, mesh, subMeshes[i1]);
18491
- renderPipeline.pushRenderData(context, renderData);
18492
- }
18493
- } else {
18494
- Logger.error("mesh is null.");
18504
+ this._dirtyUpdateFlag &= ~0x2;
18505
+ }
18506
+ var materials = this._materials;
18507
+ var subMeshes = mesh.subMeshes;
18508
+ var renderPipeline = context.camera._renderPipeline;
18509
+ var meshRenderDataPool = this._engine._meshRenderDataPool;
18510
+ for(var i1 = 0, n1 = subMeshes.length; i1 < n1; i1++){
18511
+ var material = materials[i1];
18512
+ if (!material) continue;
18513
+ var renderData = meshRenderDataPool.getFromPool();
18514
+ renderData.set(this, material, mesh, subMeshes[i1]);
18515
+ renderPipeline.pushRenderData(context, renderData);
18495
18516
  }
18496
18517
  };
18497
18518
  _proto._setMesh = function _setMesh(mesh) {
@@ -24188,18 +24209,10 @@
24188
24209
  var _config_type;
24189
24210
  config.type = (_config_type = config.type) != null ? _config_type : getMimeTypeFromUrl(url);
24190
24211
  var realRequest = config.type === "image" ? requestImage : requestRes;
24191
- var lastError;
24192
24212
  var executor = new MultiExecutor(function() {
24193
- return realRequest(url, config).onProgress(setProgress).then(function(res) {
24194
- resolve(res);
24195
- executor.stop();
24196
- }).catch(function(err) {
24197
- return lastError = err;
24198
- });
24213
+ return realRequest(url, config).onProgress(setProgress);
24199
24214
  }, retryCount, retryInterval);
24200
- executor.start(function() {
24201
- reject(lastError);
24202
- });
24215
+ executor.start().onError(reject).onComplete(resolve);
24203
24216
  });
24204
24217
  }
24205
24218
  function requestImage(url, config) {
@@ -24286,23 +24299,33 @@
24286
24299
  this.exec = this.exec.bind(this);
24287
24300
  };
24288
24301
  var _proto = MultiExecutor.prototype;
24289
- _proto.start = function start(done) {
24290
- this.done = done;
24302
+ _proto.start = function start() {
24291
24303
  this.exec();
24304
+ return this;
24292
24305
  };
24293
- _proto.stop = function stop() {
24294
- clearTimeout(this._timeoutId);
24306
+ _proto.onComplete = function onComplete(func) {
24307
+ this._onComplete = func;
24308
+ return this;
24309
+ };
24310
+ _proto.onError = function onError(func) {
24311
+ this._onError = func;
24312
+ return this;
24313
+ };
24314
+ _proto.cancel = function cancel() {
24315
+ window.clearTimeout(this._timeoutId);
24295
24316
  };
24296
24317
  _proto.exec = function exec() {
24297
24318
  var _this = this;
24298
24319
  if (this._currentCount >= this.totalCount) {
24299
- this.done && this.done();
24320
+ this._onError && this._onError(this._error);
24300
24321
  return;
24301
24322
  }
24302
24323
  this._currentCount++;
24303
- this.execFunc(this._currentCount).then(function() {
24304
- //@ts-ignore
24305
- _this._timeoutId = setTimeout(_this.exec, _this.interval);
24324
+ this.execFunc(this._currentCount).then(function(result) {
24325
+ return _this._onComplete && _this._onComplete(result);
24326
+ }).catch(function(e) {
24327
+ _this._error = e;
24328
+ _this._timeoutId = window.setTimeout(_this.exec, _this.interval);
24306
24329
  });
24307
24330
  };
24308
24331
  return MultiExecutor;
@@ -26913,92 +26936,97 @@
26913
26936
  }
26914
26937
  };
26915
26938
  _proto._updateLocalData = function _updateLocalData() {
26916
- var _this = this, color = _this.color, horizontalAlignment = _this.horizontalAlignment, verticalAlignment = _this.verticalAlignment, charRenderDatas = _this._charRenderDatas;
26939
+ var _this = this, color = _this.color, charRenderDatas = _this._charRenderDatas, charFont = _this._subFont;
26917
26940
  var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
26918
- var _pixelsPerUnit = Engine._pixelsPerUnit;
26919
- var pixelsPerUnitReciprocal = 1.0 / _pixelsPerUnit;
26920
- var charFont = this._subFont;
26921
- var rendererWidth = this.width * _pixelsPerUnit;
26922
- var halfRendererWidth = rendererWidth * 0.5;
26923
- var rendererHeight = this.height * _pixelsPerUnit;
26924
26941
  var textMetrics = this.enableWrapping ? TextUtils.measureTextWithWrap(this) : TextUtils.measureTextWithoutWrap(this);
26925
26942
  var height = textMetrics.height, lines = textMetrics.lines, lineWidths = textMetrics.lineWidths, lineHeight = textMetrics.lineHeight, lineMaxSizes = textMetrics.lineMaxSizes;
26926
26943
  var charRenderDataPool = TextRenderer._charRenderDataPool;
26927
- var halfLineHeight = lineHeight * 0.5;
26928
26944
  var linesLen = lines.length;
26929
- var startY = 0;
26930
- var topDiff = lineHeight * 0.5 - lineMaxSizes[0].ascent;
26931
- var bottomDiff = lineHeight * 0.5 - lineMaxSizes[linesLen - 1].descent - 1;
26932
- switch(verticalAlignment){
26933
- case exports.TextVerticalAlignment.Top:
26934
- startY = rendererHeight * 0.5 - halfLineHeight + topDiff;
26935
- break;
26936
- case exports.TextVerticalAlignment.Center:
26937
- startY = height * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
26938
- break;
26939
- case exports.TextVerticalAlignment.Bottom:
26940
- startY = height - rendererHeight * 0.5 - halfLineHeight - bottomDiff;
26941
- break;
26942
- }
26943
26945
  var renderDataCount = 0;
26944
- var firstLine = -1;
26945
- var minX = Number.MAX_SAFE_INTEGER;
26946
- var minY = Number.MAX_SAFE_INTEGER;
26947
- var maxX = Number.MIN_SAFE_INTEGER;
26948
- var maxY = Number.MIN_SAFE_INTEGER;
26949
- for(var i = 0; i < linesLen; ++i){
26950
- var lineWidth = lineWidths[i];
26951
- if (lineWidth > 0) {
26952
- var line = lines[i];
26953
- var startX = 0;
26954
- var firstRow = -1;
26955
- if (firstLine < 0) {
26956
- firstLine = i;
26957
- }
26958
- switch(horizontalAlignment){
26959
- case exports.TextHorizontalAlignment.Left:
26960
- startX = -halfRendererWidth;
26961
- break;
26962
- case exports.TextHorizontalAlignment.Center:
26963
- startX = -lineWidth * 0.5;
26964
- break;
26965
- case exports.TextHorizontalAlignment.Right:
26966
- startX = halfRendererWidth - lineWidth;
26967
- break;
26968
- }
26969
- for(var j = 0, n = line.length; j < n; ++j){
26970
- var char = line[j];
26971
- var charInfo = charFont._getCharInfo(char);
26972
- if (charInfo.h > 0) {
26973
- var _charRenderDatas, _ref;
26974
- firstRow < 0 && (firstRow = j);
26975
- var charRenderData = (_charRenderDatas = charRenderDatas)[_ref = renderDataCount++] || (_charRenderDatas[_ref] = charRenderDataPool.get());
26976
- var renderData = charRenderData.renderData, localPositions = charRenderData.localPositions;
26977
- charRenderData.texture = charFont._getTextureByIndex(charInfo.index);
26978
- renderData.color = color;
26979
- renderData.uvs = charInfo.uvs;
26980
- var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
26981
- var left = startX * pixelsPerUnitReciprocal;
26982
- var right = (startX + w) * pixelsPerUnitReciprocal;
26983
- var top = (startY + ascent) * pixelsPerUnitReciprocal;
26984
- var bottom = (startY - descent + 1) * pixelsPerUnitReciprocal;
26985
- localPositions.set(left, top, right, bottom);
26986
- i === firstLine && (maxY = Math.max(maxY, top));
26987
- minY = Math.min(minY, bottom);
26988
- j === firstRow && (minX = Math.min(minX, left));
26989
- maxX = Math.max(maxX, right);
26946
+ if (linesLen > 0) {
26947
+ var _pixelsPerUnit = Engine._pixelsPerUnit;
26948
+ var horizontalAlignment = this.horizontalAlignment;
26949
+ var pixelsPerUnitReciprocal = 1.0 / _pixelsPerUnit;
26950
+ var rendererWidth = this.width * _pixelsPerUnit;
26951
+ var halfRendererWidth = rendererWidth * 0.5;
26952
+ var rendererHeight = this.height * _pixelsPerUnit;
26953
+ var halfLineHeight = lineHeight * 0.5;
26954
+ var startY = 0;
26955
+ var topDiff = lineHeight * 0.5 - lineMaxSizes[0].ascent;
26956
+ var bottomDiff = lineHeight * 0.5 - lineMaxSizes[linesLen - 1].descent - 1;
26957
+ switch(this.verticalAlignment){
26958
+ case exports.TextVerticalAlignment.Top:
26959
+ startY = rendererHeight * 0.5 - halfLineHeight + topDiff;
26960
+ break;
26961
+ case exports.TextVerticalAlignment.Center:
26962
+ startY = height * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
26963
+ break;
26964
+ case exports.TextVerticalAlignment.Bottom:
26965
+ startY = height - rendererHeight * 0.5 - halfLineHeight - bottomDiff;
26966
+ break;
26967
+ }
26968
+ var firstLine = -1;
26969
+ var minX = Number.MAX_SAFE_INTEGER;
26970
+ var minY = Number.MAX_SAFE_INTEGER;
26971
+ var maxX = Number.MIN_SAFE_INTEGER;
26972
+ var maxY = Number.MIN_SAFE_INTEGER;
26973
+ for(var i = 0; i < linesLen; ++i){
26974
+ var lineWidth = lineWidths[i];
26975
+ if (lineWidth > 0) {
26976
+ var line = lines[i];
26977
+ var startX = 0;
26978
+ var firstRow = -1;
26979
+ if (firstLine < 0) {
26980
+ firstLine = i;
26981
+ }
26982
+ switch(horizontalAlignment){
26983
+ case exports.TextHorizontalAlignment.Left:
26984
+ startX = -halfRendererWidth;
26985
+ break;
26986
+ case exports.TextHorizontalAlignment.Center:
26987
+ startX = -lineWidth * 0.5;
26988
+ break;
26989
+ case exports.TextHorizontalAlignment.Right:
26990
+ startX = halfRendererWidth - lineWidth;
26991
+ break;
26992
+ }
26993
+ for(var j = 0, n = line.length; j < n; ++j){
26994
+ var char = line[j];
26995
+ var charInfo = charFont._getCharInfo(char);
26996
+ if (charInfo.h > 0) {
26997
+ var _charRenderDatas, _ref;
26998
+ firstRow < 0 && (firstRow = j);
26999
+ var charRenderData = (_charRenderDatas = charRenderDatas)[_ref = renderDataCount++] || (_charRenderDatas[_ref] = charRenderDataPool.get());
27000
+ var renderData = charRenderData.renderData, localPositions = charRenderData.localPositions;
27001
+ charRenderData.texture = charFont._getTextureByIndex(charInfo.index);
27002
+ renderData.color = color;
27003
+ renderData.uvs = charInfo.uvs;
27004
+ var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
27005
+ var left = startX * pixelsPerUnitReciprocal;
27006
+ var right = (startX + w) * pixelsPerUnitReciprocal;
27007
+ var top = (startY + ascent) * pixelsPerUnitReciprocal;
27008
+ var bottom = (startY - descent + 1) * pixelsPerUnitReciprocal;
27009
+ localPositions.set(left, top, right, bottom);
27010
+ i === firstLine && (maxY = Math.max(maxY, top));
27011
+ minY = Math.min(minY, bottom);
27012
+ j === firstRow && (minX = Math.min(minX, left));
27013
+ maxX = Math.max(maxX, right);
27014
+ }
27015
+ startX += charInfo.xAdvance;
26990
27016
  }
26991
- startX += charInfo.xAdvance;
26992
27017
  }
27018
+ startY -= lineHeight;
26993
27019
  }
26994
- startY -= lineHeight;
26995
- }
26996
- if (firstLine < 0) {
27020
+ if (firstLine < 0) {
27021
+ min.set(0, 0, 0);
27022
+ max.set(0, 0, 0);
27023
+ } else {
27024
+ min.set(minX, minY, 0);
27025
+ max.set(maxX, maxY, 0);
27026
+ }
27027
+ } else {
26997
27028
  min.set(0, 0, 0);
26998
27029
  max.set(0, 0, 0);
26999
- } else {
27000
- min.set(minX, minY, 0);
27001
- max.set(maxX, maxY, 0);
27002
27030
  }
27003
27031
  // Revert excess render data to pool.
27004
27032
  var lastRenderDataCount = charRenderDatas.length;
@@ -28981,7 +29009,8 @@
28981
29009
  };
28982
29010
  _proto._saveAnimatorEventHandlers = function _saveAnimatorEventHandlers(state, animatorStateData) {
28983
29011
  var eventHandlerPool = this._animationEventHandlerPool;
28984
- var scripts = this._entity._scripts;
29012
+ var scripts = [];
29013
+ this._entity.getComponents(Script, scripts);
28985
29014
  var scriptCount = scripts.length;
28986
29015
  var eventHandlers = animatorStateData.eventHandlers;
28987
29016
  var events = state.clip.events;
@@ -28994,7 +29023,7 @@
28994
29023
  eventHandler.event = event;
28995
29024
  handlers.length = 0;
28996
29025
  for(var j = scriptCount - 1; j >= 0; j--){
28997
- var handler = scripts.get(j)[funcName];
29026
+ var handler = scripts[j][funcName];
28998
29027
  handler && handlers.push(handler);
28999
29028
  }
29000
29029
  eventHandlers.push(eventHandler);
@@ -33731,7 +33760,8 @@
33731
33760
  state.wrapMode = wrapMode;
33732
33761
  state.clipStartTime = clipStartNormalizedTime;
33733
33762
  state.clipEndTime = clipEndNormalizedTime;
33734
- scripts == null ? void 0 : scripts.forEach(function(script) {
33763
+ var scriptsObject = JSON.parse(scripts);
33764
+ scriptsObject == null ? void 0 : scriptsObject.forEach(function(script) {
33735
33765
  state.addStateMachineScript(Loader.getClass(script));
33736
33766
  });
33737
33767
  if (clipData) {
@@ -34036,15 +34066,18 @@
34036
34066
  for(var _iterator2 = _create_for_of_iterator_helper_loose(meshInfo.blendShapes), _step2; !(_step2 = _iterator2()).done;){
34037
34067
  var restoreInfo = _step2.value;
34038
34068
  var frame = restoreInfo.blendShape.frames[0];
34039
- var positionData = _this._getBufferData(buffers, restoreInfo.position);
34040
- frame.deltaPositions = GLTFUtils.floatBufferToVector3Array(positionData);
34069
+ var position = restoreInfo.position;
34070
+ var positionData = _this._getBufferData(buffers, position.buffer);
34071
+ frame.deltaPositions = GLTFUtils.bufferToVector3Array(positionData, position.stride, position.byteOffset, position.count);
34041
34072
  if (restoreInfo.normal) {
34042
- var normalData = _this._getBufferData(buffers, restoreInfo.normal);
34043
- frame.deltaNormals = GLTFUtils.floatBufferToVector3Array(normalData);
34073
+ var normal = restoreInfo.normal;
34074
+ var normalData = _this._getBufferData(buffers, normal.buffer);
34075
+ frame.deltaNormals = GLTFUtils.bufferToVector3Array(normalData, normal.stride, normal.byteOffset, normal.count);
34044
34076
  }
34045
34077
  if (restoreInfo.tangent) {
34046
- var tangentData = _this._getBufferData(buffers, restoreInfo.tangent);
34047
- frame.deltaTangents = GLTFUtils.floatBufferToVector3Array(tangentData);
34078
+ var tangent = restoreInfo.tangent;
34079
+ var tangentData = _this._getBufferData(buffers, tangent.buffer);
34080
+ frame.deltaTangents = GLTFUtils.bufferToVector3Array(tangentData, tangent.stride, tangent.byteOffset, tangent.count);
34048
34081
  }
34049
34082
  }
34050
34083
  mesh.uploadData(true);
@@ -34128,6 +34161,14 @@
34128
34161
  this.normal = normal;
34129
34162
  this.tangent = tangent;
34130
34163
  };
34164
+ /**
34165
+ * @internal
34166
+ */ var BlendShapeDataRestoreInfo = function BlendShapeDataRestoreInfo(buffer, stride, byteOffset, count) {
34167
+ this.buffer = buffer;
34168
+ this.stride = stride;
34169
+ this.byteOffset = byteOffset;
34170
+ this.count = count;
34171
+ };
34131
34172
  /**
34132
34173
  * Module for glTF 2.0 Interface
34133
34174
  */ var AccessorComponentType;
@@ -34297,6 +34338,11 @@
34297
34338
  promiseMap["" + url] = this._initPromiseInfo(this.masterPromiseInfo);
34298
34339
  };
34299
34340
  var _proto = GLTFParserContext.prototype;
34341
+ /**
34342
+ * Get all the buffer data.
34343
+ */ _proto.getBuffers = function getBuffers() {
34344
+ return Promise.resolve(this._buffers);
34345
+ };
34300
34346
  _proto._initPromiseInfo = function _initPromiseInfo(promiseInfo) {
34301
34347
  var promise = new AssetPromise(function(resolve, reject, setProgress, onCancel) {
34302
34348
  promiseInfo.resolve = resolve;
@@ -34416,44 +34462,58 @@
34416
34462
  }
34417
34463
  };
34418
34464
  GLTFUtils.getAccessorBuffer = function getAccessorBuffer(context, bufferViews, accessor) {
34419
- var buffers = context.buffers;
34420
34465
  var componentType = accessor.componentType;
34421
34466
  var bufferView = bufferViews[accessor.bufferView];
34422
- var bufferIndex = bufferView.buffer;
34423
- var buffer = buffers[bufferIndex];
34424
- var bufferByteOffset = bufferView.byteOffset || 0;
34425
- var byteOffset = accessor.byteOffset || 0;
34426
- var TypedArray = GLTFUtils.getComponentType(componentType);
34427
- var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
34428
- var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
34429
- var elementStride = dataElementSize * dataElementBytes;
34430
- var accessorCount = accessor.count;
34431
- var bufferStride = bufferView.byteStride;
34432
- var bufferInfo;
34433
- // According to the glTF official documentation only byteStride not undefined is allowed
34434
- if (bufferStride !== undefined && bufferStride !== elementStride) {
34435
- var bufferSlice = Math.floor(byteOffset / bufferStride);
34436
- var bufferCacheKey = accessor.bufferView + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
34437
- var accessorBufferCache = context.accessorBufferCache;
34438
- bufferInfo = accessorBufferCache[bufferCacheKey];
34439
- if (!bufferInfo) {
34440
- var offset = bufferByteOffset + bufferSlice * bufferStride;
34441
- var count = accessorCount * (bufferStride / dataElementBytes);
34442
- var data = new TypedArray(buffer, offset, count);
34443
- accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
34444
- bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
34467
+ return context.getBuffers().then(function(buffers) {
34468
+ var bufferIndex = bufferView.buffer;
34469
+ var buffer = buffers[bufferIndex];
34470
+ var _bufferView_byteOffset;
34471
+ var bufferByteOffset = (_bufferView_byteOffset = bufferView.byteOffset) != null ? _bufferView_byteOffset : 0;
34472
+ var _accessor_byteOffset;
34473
+ var byteOffset = (_accessor_byteOffset = accessor.byteOffset) != null ? _accessor_byteOffset : 0;
34474
+ var TypedArray = GLTFUtils.getComponentType(componentType);
34475
+ var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
34476
+ var dataElementBytes = TypedArray.BYTES_PER_ELEMENT;
34477
+ var elementStride = dataElementSize * dataElementBytes;
34478
+ var accessorCount = accessor.count;
34479
+ var bufferStride = bufferView.byteStride;
34480
+ var bufferInfo;
34481
+ // According to the glTF official documentation only byteStride not undefined is allowed
34482
+ if (bufferStride !== undefined && bufferStride !== elementStride) {
34483
+ var bufferSlice = Math.floor(byteOffset / bufferStride);
34484
+ var bufferCacheKey = accessor.bufferView + ":" + componentType + ":" + bufferSlice + ":" + accessorCount;
34485
+ var accessorBufferCache = context.accessorBufferCache;
34486
+ bufferInfo = accessorBufferCache[bufferCacheKey];
34487
+ if (!bufferInfo) {
34488
+ var offset = bufferByteOffset + bufferSlice * bufferStride;
34489
+ var count = accessorCount * (bufferStride / dataElementBytes);
34490
+ var data = new TypedArray(buffer, offset, count);
34491
+ accessorBufferCache[bufferCacheKey] = bufferInfo = new BufferInfo(data, true, bufferStride);
34492
+ bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset, count));
34493
+ }
34494
+ } else {
34495
+ var offset1 = bufferByteOffset + byteOffset;
34496
+ var count1 = accessorCount * dataElementSize;
34497
+ var data1 = new TypedArray(buffer, offset1, count1);
34498
+ bufferInfo = new BufferInfo(data1, false, elementStride);
34499
+ bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
34445
34500
  }
34446
- } else {
34447
- var offset1 = bufferByteOffset + byteOffset;
34448
- var count1 = accessorCount * dataElementSize;
34449
- var data1 = new TypedArray(buffer, offset1, count1);
34450
- bufferInfo = new BufferInfo(data1, false, elementStride);
34451
- bufferInfo.restoreInfo = new BufferDataRestoreInfo(new RestoreDataAccessor(bufferIndex, TypedArray, offset1, count1));
34452
- }
34453
- if (accessor.sparse) {
34454
- GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
34501
+ if (accessor.sparse) {
34502
+ GLTFUtils.processingSparseData(bufferViews, accessor, buffers, bufferInfo);
34503
+ }
34504
+ return bufferInfo;
34505
+ });
34506
+ };
34507
+ GLTFUtils.bufferToVector3Array = function bufferToVector3Array(data, byteStride, accessorByteOffset, count) {
34508
+ var bytesPerElement = data.BYTES_PER_ELEMENT;
34509
+ var offset = accessorByteOffset % byteStride / bytesPerElement;
34510
+ var stride = byteStride / bytesPerElement;
34511
+ var vector3s = new Array(count);
34512
+ for(var i = 0; i < count; i++){
34513
+ var index = offset + i * stride;
34514
+ vector3s[i] = new Vector3(data[index], data[index + 1], data[index + 2]);
34455
34515
  }
34456
- return bufferInfo;
34516
+ return vector3s;
34457
34517
  };
34458
34518
  /**
34459
34519
  * @deprecated
@@ -34912,9 +34972,7 @@
34912
34972
  _inherits(GLTFAnimationParser, GLTFParser1);
34913
34973
  var _proto = GLTFAnimationParser.prototype;
34914
34974
  _proto.parse = function parse(context) {
34915
- var glTF = context.glTF;
34916
- context.buffers;
34917
- var glTFResource = context.glTFResource;
34975
+ var glTF = context.glTF, glTFResource = context.glTFResource;
34918
34976
  glTFResource.entities;
34919
34977
  var animations = glTF.animations;
34920
34978
  glTF.accessors;
@@ -34926,106 +34984,120 @@
34926
34984
  var animationClipCount = animations.length;
34927
34985
  var animationClipPromises = [];
34928
34986
  new Array(animationClipCount);
34987
+ var parseStandardPropertyPromises = new Array();
34929
34988
  for(var i = 0; i < animationClipCount; i++){
34930
34989
  var animationInfo = animations[i];
34931
34990
  var _animationInfo_name = animationInfo.name, name = _animationInfo_name === void 0 ? "AnimationClip" + i : _animationInfo_name;
34932
34991
  var animationClip = GLTFParser.executeExtensionsCreateAndParse(animationInfo.extensions, context, animationInfo);
34933
34992
  if (!animationClip) {
34934
34993
  animationClip = new AnimationClip(name);
34935
- GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo);
34994
+ parseStandardPropertyPromises.push(GLTFAnimationParser._parseStandardProperty(context, animationClip, animationInfo));
34936
34995
  }
34937
34996
  animationClipPromises.push(animationClip);
34938
34997
  }
34939
- return AssetPromise.all(animationClipPromises).then(function(animationClips) {
34940
- glTFResource.animations = animationClips;
34941
- for(var i = 0; i < glTF.animations.length; i++){
34942
- var animationInfo = glTF.animations[i];
34943
- GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
34944
- }
34945
- animationClipsPromiseInfo.resolve(animationClips);
34946
- return animationClipsPromiseInfo.promise;
34998
+ return AssetPromise.all(parseStandardPropertyPromises).then(function() {
34999
+ return AssetPromise.all(animationClipPromises).then(function(animationClips) {
35000
+ glTFResource.animations = animationClips;
35001
+ for(var i = 0; i < glTF.animations.length; i++){
35002
+ var animationInfo = glTF.animations[i];
35003
+ GLTFParser.executeExtensionsAdditiveAndParse(animationInfo.extensions, context, animationClips[i], animationInfo);
35004
+ }
35005
+ animationClipsPromiseInfo.resolve(animationClips);
35006
+ return animationClipsPromiseInfo.promise;
35007
+ });
34947
35008
  });
34948
35009
  };
34949
35010
  /**
34950
35011
  * @internal
34951
35012
  */ GLTFAnimationParser._parseStandardProperty = function _parseStandardProperty(context, animationClip, animationInfo) {
35013
+ var _loop = function _loop(j, m) {
35014
+ var gltfSampler = samplers[j];
35015
+ var inputAccessor = accessors[gltfSampler.input];
35016
+ var outputAccessor = accessors[gltfSampler.output];
35017
+ var promise = Promise.all([
35018
+ GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor),
35019
+ GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor)
35020
+ ]).then(function(bufferInfos) {
35021
+ var input = bufferInfos[0].data;
35022
+ var output = bufferInfos[1].data;
35023
+ if (outputAccessor.normalized) {
35024
+ var scale = GLTFUtils.getNormalizedComponentScale(outputAccessor.componentType);
35025
+ var scaled = new Float32Array(output.length);
35026
+ for(var k = 0, v = output.length; k < v; k++){
35027
+ scaled[k] = output[k] * scale;
35028
+ }
35029
+ output = scaled;
35030
+ }
35031
+ var outputStride = output.length / input.length;
35032
+ var _gltfSampler_interpolation;
35033
+ var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
35034
+ var samplerInterpolation;
35035
+ switch(interpolation){
35036
+ case AnimationSamplerInterpolation.CubicSpine:
35037
+ samplerInterpolation = exports.InterpolationType.CubicSpine;
35038
+ break;
35039
+ case AnimationSamplerInterpolation.Step:
35040
+ samplerInterpolation = exports.InterpolationType.Step;
35041
+ break;
35042
+ case AnimationSamplerInterpolation.Linear:
35043
+ samplerInterpolation = exports.InterpolationType.Linear;
35044
+ break;
35045
+ }
35046
+ input[input.length - 1];
35047
+ sampleDataCollection.push({
35048
+ type: outputAccessor.type,
35049
+ interpolation: samplerInterpolation,
35050
+ input: input,
35051
+ output: output,
35052
+ outputSize: outputStride
35053
+ });
35054
+ });
35055
+ promises.push(promise);
35056
+ };
35057
+ var _this = this;
34952
35058
  var glTF = context.glTF, glTFResource = context.glTFResource;
34953
35059
  var entities = glTFResource.entities;
34954
35060
  var accessors = glTF.accessors, bufferViews = glTF.bufferViews;
34955
35061
  var channels = animationInfo.channels, samplers = animationInfo.samplers;
34956
35062
  var sampleDataCollection = new Array();
35063
+ var promises = new Array();
34957
35064
  // parse samplers
34958
- for(var j = 0, m = samplers.length; j < m; j++){
34959
- var gltfSampler = samplers[j];
34960
- var inputAccessor = accessors[gltfSampler.input];
34961
- var outputAccessor = accessors[gltfSampler.output];
34962
- var input = GLTFUtils.getAccessorBuffer(context, bufferViews, inputAccessor).data;
34963
- var output = GLTFUtils.getAccessorBuffer(context, bufferViews, outputAccessor).data;
34964
- if (outputAccessor.normalized) {
34965
- var scale = GLTFUtils.getNormalizedComponentScale(outputAccessor.componentType);
34966
- var scaled = new Float32Array(output.length);
34967
- for(var k = 0, v = output.length; k < v; k++){
34968
- scaled[k] = output[k] * scale;
34969
- }
34970
- output = scaled;
34971
- }
34972
- var outputStride = output.length / input.length;
34973
- var _gltfSampler_interpolation;
34974
- var interpolation = (_gltfSampler_interpolation = gltfSampler.interpolation) != null ? _gltfSampler_interpolation : AnimationSamplerInterpolation.Linear;
34975
- var samplerInterpolation = void 0;
34976
- switch(interpolation){
34977
- case AnimationSamplerInterpolation.CubicSpine:
34978
- samplerInterpolation = exports.InterpolationType.CubicSpine;
34979
- break;
34980
- case AnimationSamplerInterpolation.Step:
34981
- samplerInterpolation = exports.InterpolationType.Step;
34982
- break;
34983
- case AnimationSamplerInterpolation.Linear:
34984
- samplerInterpolation = exports.InterpolationType.Linear;
34985
- break;
34986
- }
34987
- input[input.length - 1];
34988
- sampleDataCollection.push({
34989
- type: outputAccessor.type,
34990
- interpolation: samplerInterpolation,
34991
- input: input,
34992
- output: output,
34993
- outputSize: outputStride
34994
- });
34995
- }
34996
- for(var j1 = 0, m1 = channels.length; j1 < m1; j1++){
34997
- var gltfChannel = channels[j1];
34998
- var target = gltfChannel.target;
34999
- var channelTargetEntity = entities[target.node];
35000
- var relativePath = "";
35001
- var entity = channelTargetEntity;
35002
- while(entity.parent){
35003
- relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
35004
- entity = entity.parent;
35005
- }
35006
- var ComponentType = void 0;
35007
- var propertyName = void 0;
35008
- switch(target.path){
35009
- case AnimationChannelTargetPath.TRANSLATION:
35010
- ComponentType = Transform;
35011
- propertyName = "position";
35012
- break;
35013
- case AnimationChannelTargetPath.ROTATION:
35014
- ComponentType = Transform;
35015
- propertyName = "rotationQuaternion";
35016
- break;
35017
- case AnimationChannelTargetPath.SCALE:
35018
- ComponentType = Transform;
35019
- propertyName = "scale";
35020
- break;
35021
- case AnimationChannelTargetPath.WEIGHTS:
35022
- ComponentType = SkinnedMeshRenderer;
35023
- propertyName = "blendShapeWeights";
35024
- break;
35065
+ for(var j = 0, m = samplers.length; j < m; j++)_loop(j);
35066
+ return Promise.all(promises).then(function() {
35067
+ for(var j = 0, m = channels.length; j < m; j++){
35068
+ var gltfChannel = channels[j];
35069
+ var target = gltfChannel.target;
35070
+ var channelTargetEntity = entities[target.node];
35071
+ var relativePath = "";
35072
+ var entity = channelTargetEntity;
35073
+ while(entity.parent){
35074
+ relativePath = relativePath === "" ? "" + entity.name : entity.name + "/" + relativePath;
35075
+ entity = entity.parent;
35076
+ }
35077
+ var ComponentType = void 0;
35078
+ var propertyName = void 0;
35079
+ switch(target.path){
35080
+ case AnimationChannelTargetPath.TRANSLATION:
35081
+ ComponentType = Transform;
35082
+ propertyName = "position";
35083
+ break;
35084
+ case AnimationChannelTargetPath.ROTATION:
35085
+ ComponentType = Transform;
35086
+ propertyName = "rotationQuaternion";
35087
+ break;
35088
+ case AnimationChannelTargetPath.SCALE:
35089
+ ComponentType = Transform;
35090
+ propertyName = "scale";
35091
+ break;
35092
+ case AnimationChannelTargetPath.WEIGHTS:
35093
+ ComponentType = SkinnedMeshRenderer;
35094
+ propertyName = "blendShapeWeights";
35095
+ break;
35096
+ }
35097
+ var curve = _this._addCurve(target.path, gltfChannel, sampleDataCollection);
35098
+ animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
35025
35099
  }
35026
- var curve = this._addCurve(target.path, gltfChannel, sampleDataCollection);
35027
- animationClip.addCurveBinding(relativePath, ComponentType, propertyName, curve);
35028
- }
35100
+ });
35029
35101
  };
35030
35102
  GLTFAnimationParser._addCurve = function _addCurve(animationChannelTargetPath, gltfChannel, sampleDataCollection) {
35031
35103
  var sampleData = sampleDataCollection[gltfChannel.sampler];
@@ -35119,20 +35191,18 @@
35119
35191
  }).then(function(param) {
35120
35192
  var glTF = param.glTF, buffers = param.buffers;
35121
35193
  context.glTF = glTF;
35122
- context.buffers = buffers;
35194
+ context._buffers = buffers;
35123
35195
  });
35124
35196
  } else {
35125
35197
  return request(url, {
35126
35198
  type: "json"
35127
35199
  }).then(function(glTF) {
35128
35200
  context.glTF = glTF;
35129
- return Promise.all(glTF.buffers.map(function(buffer) {
35201
+ context._buffers = Promise.all(glTF.buffers.map(function(buffer) {
35130
35202
  var absoluteUrl = Utils.resolveAbsoluteUrl(url, buffer.uri);
35131
35203
  restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig));
35132
35204
  return request(absoluteUrl, requestConfig);
35133
- })).then(function(buffers) {
35134
- context.buffers = buffers;
35135
- });
35205
+ }));
35136
35206
  });
35137
35207
  }
35138
35208
  };
@@ -35377,7 +35447,9 @@
35377
35447
  }
35378
35448
  }, function() {
35379
35449
  var indexAccessor = glTF.accessors[gltfPrimitive.indices];
35380
- return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
35450
+ return context.getBuffers().then(function(buffers) {
35451
+ return GLTFUtils.getAccessorData(glTF, indexAccessor, buffers);
35452
+ });
35381
35453
  }, context.keepMeshData).then(resolve);
35382
35454
  }
35383
35455
  });
@@ -35387,7 +35459,7 @@
35387
35459
  for(var j = 0; j < gltfMesh.primitives.length; j++)_loop(j);
35388
35460
  meshPromises[i] = Promise.all(primitivePromises);
35389
35461
  };
35390
- var glTF = context.glTF, buffers = context.buffers, glTFResource = context.glTFResource;
35462
+ var glTF = context.glTF, glTFResource = context.glTFResource;
35391
35463
  var engine = glTFResource.engine;
35392
35464
  if (!glTF.meshes) return;
35393
35465
  var meshesPromiseInfo = context.meshesPromiseInfo;
@@ -35402,8 +35474,109 @@
35402
35474
  /**
35403
35475
  * @internal
35404
35476
  */ GLTFMeshParser._parseMeshFromGLTFPrimitive = function _parseMeshFromGLTFPrimitive(context, mesh, meshRestoreInfo, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
35477
+ var _loop = function _loop(attribute) {
35478
+ var accessor = accessors[attributes[attribute]];
35479
+ var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor).then(function(accessorBuffer) {
35480
+ var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
35481
+ var accessorCount = accessor.count;
35482
+ var vertices = accessorBuffer.data;
35483
+ var vertexElement;
35484
+ var meshId = mesh.instanceId;
35485
+ var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
35486
+ var elementNormalized = accessor.normalized;
35487
+ var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
35488
+ var scaleFactor;
35489
+ elementNormalized && (scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType));
35490
+ var elementOffset;
35491
+ if (accessorBuffer.interleaved) {
35492
+ var byteOffset = accessor.byteOffset || 0;
35493
+ var stride = accessorBuffer.stride;
35494
+ elementOffset = byteOffset % stride;
35495
+ if (vertexBindingInfos[meshId] === undefined) {
35496
+ vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
35497
+ var vertexBuffer = accessorBuffer.vertexBuffer;
35498
+ if (!vertexBuffer) {
35499
+ vertexBuffer = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices.byteLength, exports.BufferUsage.Static);
35500
+ vertexBuffer.setData(vertices);
35501
+ accessorBuffer.vertexBuffer = vertexBuffer;
35502
+ meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
35503
+ }
35504
+ mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
35505
+ vertexBindingInfos[meshId] = bufferBindIndex++;
35506
+ } else {
35507
+ vertexElement = new VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
35508
+ }
35509
+ } else {
35510
+ elementOffset = 0;
35511
+ vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
35512
+ var vertexBuffer1 = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices.byteLength, exports.BufferUsage.Static);
35513
+ vertexBuffer1.setData(vertices);
35514
+ meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
35515
+ mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
35516
+ vertexBindingInfos[meshId] = bufferBindIndex++;
35517
+ }
35518
+ vertexElements.push(vertexElement);
35519
+ if (attribute === "POSITION") {
35520
+ vertexCount = accessorCount;
35521
+ var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
35522
+ if (accessor.min && accessor.max) {
35523
+ min.copyFromArray(accessor.min);
35524
+ max.copyFromArray(accessor.max);
35525
+ if (keepMeshData) {
35526
+ var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
35527
+ var stride1 = vertices.length / accessorCount;
35528
+ for(var j = 0; j < accessorCount; j++){
35529
+ var offset = baseOffset + j * stride1;
35530
+ var position = new Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
35531
+ elementNormalized && position.scale(scaleFactor);
35532
+ positions[j] = position;
35533
+ }
35534
+ }
35535
+ } else {
35536
+ var position1 = GLTFMeshParser._tempVector3;
35537
+ min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
35538
+ max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
35539
+ var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
35540
+ var stride2 = vertices.length / accessorCount;
35541
+ for(var j1 = 0; j1 < accessorCount; j1++){
35542
+ var offset1 = baseOffset1 + j1 * stride2;
35543
+ position1.copyFromArray(vertices, offset1);
35544
+ Vector3.min(min, position1, min);
35545
+ Vector3.max(max, position1, max);
35546
+ if (keepMeshData) {
35547
+ var clonePosition = position1.clone();
35548
+ elementNormalized && clonePosition.scale(scaleFactor);
35549
+ positions[j1] = clonePosition;
35550
+ }
35551
+ }
35552
+ }
35553
+ if (elementNormalized) {
35554
+ min.scale(scaleFactor);
35555
+ max.scale(scaleFactor);
35556
+ }
35557
+ } else if (attribute === "JOINTS_0" && keepMeshData) {
35558
+ var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
35559
+ var stride3 = vertices.length / accessorCount;
35560
+ for(var j2 = 0; j2 < accessorCount; j2++){
35561
+ var offset2 = baseOffset2 + j2 * stride3;
35562
+ var boneIndex = new Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
35563
+ elementNormalized && boneIndex.scale(scaleFactor);
35564
+ boneIndices[j2] = boneIndex;
35565
+ }
35566
+ } else if (attribute === "WEIGHTS_0" && keepMeshData) {
35567
+ var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
35568
+ var stride4 = vertices.length / accessorCount;
35569
+ for(var j3 = 0; j3 < accessorCount; j3++){
35570
+ var offset3 = baseOffset3 + j3 * stride4;
35571
+ var boneWeight = new Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
35572
+ elementNormalized && boneWeight.scale(scaleFactor);
35573
+ boneWeights[j3] = boneWeight;
35574
+ }
35575
+ }
35576
+ });
35577
+ promises.push(promise);
35578
+ };
35405
35579
  var accessors = gltf.accessors;
35406
- context.buffers;
35407
35580
  var attributes = gltfPrimitive.attributes, targets = gltfPrimitive.targets, indices = gltfPrimitive.indices, mode = gltfPrimitive.mode;
35408
35581
  var engine = mesh.engine;
35409
35582
  var vertexElements = new Array();
@@ -35417,145 +35590,85 @@
35417
35590
  boneIndices = new Array(vertexCount);
35418
35591
  boneWeights = new Array(vertexCount);
35419
35592
  }
35420
- for(var attribute in attributes){
35421
- var accessor = accessors[attributes[attribute]];
35422
- var accessorBuffer = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor);
35423
- var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
35424
- var accessorCount = accessor.count;
35425
- var vertices = accessorBuffer.data;
35426
- var vertexElement = void 0;
35427
- var meshId = mesh.instanceId;
35428
- var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
35429
- var elementNormalized = accessor.normalized;
35430
- var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
35431
- var scaleFactor = void 0;
35432
- elementNormalized && (scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType));
35433
- var elementOffset = void 0;
35434
- if (accessorBuffer.interleaved) {
35435
- var byteOffset = accessor.byteOffset || 0;
35436
- var stride = accessorBuffer.stride;
35437
- elementOffset = byteOffset % stride;
35438
- if (vertexBindingInfos[meshId] === undefined) {
35439
- vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
35440
- var vertexBuffer = accessorBuffer.vertexBuffer;
35441
- if (!vertexBuffer) {
35442
- vertexBuffer = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices.byteLength, exports.BufferUsage.Static);
35443
- vertexBuffer.setData(vertices);
35444
- accessorBuffer.vertexBuffer = vertexBuffer;
35445
- meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer, accessorBuffer.restoreInfo));
35446
- }
35447
- mesh.setVertexBufferBinding(vertexBuffer, stride, bufferBindIndex);
35448
- vertexBindingInfos[meshId] = bufferBindIndex++;
35449
- } else {
35450
- vertexElement = new VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
35451
- }
35593
+ var promises = new Array();
35594
+ for(var attribute in attributes)_loop(attribute);
35595
+ return Promise.all(promises).then(function() {
35596
+ mesh.setVertexElements(vertexElements);
35597
+ // Indices
35598
+ if (indices !== undefined) {
35599
+ var indexAccessor = gltf.accessors[indices];
35600
+ var promise = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor).then(function(accessorBuffer) {
35601
+ mesh.setIndices(accessorBuffer.data);
35602
+ mesh.addSubMesh(0, indexAccessor.count, mode);
35603
+ meshRestoreInfo.indexBuffer = accessorBuffer.restoreInfo;
35604
+ });
35605
+ promises.push(promise);
35452
35606
  } else {
35453
- elementOffset = 0;
35454
- vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
35455
- var vertexBuffer1 = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices.byteLength, exports.BufferUsage.Static);
35456
- vertexBuffer1.setData(vertices);
35457
- meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
35458
- mesh.setVertexBufferBinding(vertexBuffer1, accessorBuffer.stride, bufferBindIndex);
35459
- vertexBindingInfos[meshId] = bufferBindIndex++;
35460
- }
35461
- vertexElements.push(vertexElement);
35462
- if (attribute === "POSITION") {
35463
- vertexCount = accessorCount;
35464
- var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
35465
- if (accessor.min && accessor.max) {
35466
- min.copyFromArray(accessor.min);
35467
- max.copyFromArray(accessor.max);
35468
- if (keepMeshData) {
35469
- var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
35470
- var stride1 = vertices.length / accessorCount;
35471
- for(var j = 0; j < accessorCount; j++){
35472
- var offset = baseOffset + j * stride1;
35473
- var position = new Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
35474
- elementNormalized && position.scale(scaleFactor);
35475
- positions[j] = position;
35476
- }
35477
- }
35478
- } else {
35479
- var position1 = GLTFMeshParser._tempVector3;
35480
- min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
35481
- max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
35482
- var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
35483
- var stride2 = vertices.length / accessorCount;
35484
- for(var j1 = 0; j1 < accessorCount; j1++){
35485
- var offset1 = baseOffset1 + j1 * stride2;
35486
- position1.copyFromArray(vertices, offset1);
35487
- Vector3.min(min, position1, min);
35488
- Vector3.max(max, position1, max);
35489
- if (keepMeshData) {
35490
- var clonePosition = position1.clone();
35491
- elementNormalized && clonePosition.scale(scaleFactor);
35492
- positions[j1] = clonePosition;
35493
- }
35494
- }
35495
- }
35496
- if (elementNormalized) {
35497
- min.scale(scaleFactor);
35498
- max.scale(scaleFactor);
35499
- }
35500
- } else if (attribute === "JOINTS_0" && keepMeshData) {
35501
- var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
35502
- var stride3 = vertices.length / accessorCount;
35503
- for(var j2 = 0; j2 < accessorCount; j2++){
35504
- var offset2 = baseOffset2 + j2 * stride3;
35505
- var boneIndex = new Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
35506
- elementNormalized && boneIndex.scale(scaleFactor);
35507
- boneIndices[j2] = boneIndex;
35508
- }
35509
- } else if (attribute === "WEIGHTS_0" && keepMeshData) {
35510
- var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
35511
- var stride4 = vertices.length / accessorCount;
35512
- for(var j3 = 0; j3 < accessorCount; j3++){
35513
- var offset3 = baseOffset3 + j3 * stride4;
35514
- var boneWeight = new Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
35515
- elementNormalized && boneWeight.scale(scaleFactor);
35516
- boneWeights[j3] = boneWeight;
35517
- }
35518
- }
35519
- }
35520
- mesh.setVertexElements(vertexElements);
35521
- // Indices
35522
- if (indices !== undefined) {
35523
- var indexAccessor = gltf.accessors[indices];
35524
- var accessorBuffer1 = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, indexAccessor);
35525
- mesh.setIndices(accessorBuffer1.data);
35526
- mesh.addSubMesh(0, indexAccessor.count, mode);
35527
- meshRestoreInfo.indexBuffer = accessorBuffer1.restoreInfo;
35528
- } else {
35529
- mesh.addSubMesh(0, vertexCount, mode);
35530
- }
35531
- // BlendShapes
35532
- targets && GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, targets, getBlendShapeData);
35533
- mesh.uploadData(!keepMeshData);
35534
- //@ts-ignore
35535
- mesh._positions = positions;
35536
- //@ts-ignore
35537
- mesh._boneIndices = boneIndices;
35538
- //@ts-ignore
35539
- mesh._boneWeights = boneWeights;
35540
- return Promise.resolve(mesh);
35607
+ mesh.addSubMesh(0, vertexCount, mode);
35608
+ }
35609
+ // BlendShapes
35610
+ if (targets) {
35611
+ promises.push(GLTFMeshParser._createBlendShape(mesh, meshRestoreInfo, gltfMesh, accessors, targets, getBlendShapeData));
35612
+ }
35613
+ return Promise.all(promises).then(function() {
35614
+ mesh.uploadData(!keepMeshData);
35615
+ //@ts-ignore
35616
+ mesh._positions = positions;
35617
+ //@ts-ignore
35618
+ mesh._boneIndices = boneIndices;
35619
+ //@ts-ignore
35620
+ mesh._boneWeights = boneWeights;
35621
+ return Promise.resolve(mesh);
35622
+ });
35623
+ });
35541
35624
  };
35542
35625
  /**
35543
35626
  * @internal
35544
- */ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, glTFTargets, getBlendShapeData) {
35545
- var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
35546
- for(var i = 0, n = glTFTargets.length; i < n; i++){
35627
+ */ GLTFMeshParser._createBlendShape = function _createBlendShape(mesh, meshRestoreInfo, glTFMesh, accessors, glTFTargets, getBlendShapeData) {
35628
+ var _loop = function _loop(i, n) {
35547
35629
  var name = blendShapeNames ? blendShapeNames[i] : "blendShape" + i;
35548
- var deltaPosBufferInfo = getBlendShapeData("POSITION", i);
35549
- var deltaNorBufferInfo = getBlendShapeData("NORMAL", i);
35550
- var deltaTanBufferInfo = getBlendShapeData("TANGENT", i);
35551
- var deltaPositions = deltaPosBufferInfo.data ? GLTFUtils.floatBufferToVector3Array(deltaPosBufferInfo.data) : null;
35552
- var deltaNormals = (deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.data) : null;
35553
- var deltaTangents = (deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) ? GLTFUtils.floatBufferToVector3Array(deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.data) : null;
35554
- var blendShape = new BlendShape(name);
35555
- blendShape.addFrame(1.0, deltaPositions, deltaNormals, deltaTangents);
35556
- mesh.addBlendShape(blendShape);
35557
- meshRestoreInfo.blendShapes.push(new BlendShapeRestoreInfo(blendShape, deltaPosBufferInfo.restoreInfo, deltaNorBufferInfo == null ? void 0 : deltaNorBufferInfo.restoreInfo, deltaTanBufferInfo == null ? void 0 : deltaTanBufferInfo.restoreInfo));
35558
- }
35630
+ var promise = Promise.all([
35631
+ getBlendShapeData("POSITION", i),
35632
+ getBlendShapeData("NORMAL", i),
35633
+ getBlendShapeData("TANGENT", i)
35634
+ ]).then(function(infos) {
35635
+ var posBufferInfo = infos[0];
35636
+ var norBufferInfo = infos[1];
35637
+ var tanBufferInfo = infos[2];
35638
+ var target = glTFTargets[i];
35639
+ var posAccessor;
35640
+ var norAccessor;
35641
+ var tanAccessor;
35642
+ var positions = null;
35643
+ if (posBufferInfo) {
35644
+ posAccessor = accessors[target["POSITION"]];
35645
+ var _posAccessor_byteOffset;
35646
+ positions = GLTFUtils.bufferToVector3Array(posBufferInfo.data, posBufferInfo.stride, (_posAccessor_byteOffset = posAccessor.byteOffset) != null ? _posAccessor_byteOffset : 0, posAccessor.count);
35647
+ }
35648
+ var normals = null;
35649
+ if (norBufferInfo) {
35650
+ norAccessor = accessors[target["NORMAL"]];
35651
+ var _norAccessor_byteOffset;
35652
+ normals = GLTFUtils.bufferToVector3Array(norBufferInfo.data, norBufferInfo.stride, (_norAccessor_byteOffset = norAccessor.byteOffset) != null ? _norAccessor_byteOffset : 0, norAccessor.count);
35653
+ }
35654
+ var tangents = null;
35655
+ if (tanBufferInfo) {
35656
+ tanAccessor = accessors[target["NORMAL"]];
35657
+ var _tanAccessor_byteOffset;
35658
+ tangents = GLTFUtils.bufferToVector3Array(tanBufferInfo.data, tanBufferInfo.stride, (_tanAccessor_byteOffset = tanAccessor.byteOffset) != null ? _tanAccessor_byteOffset : 0, tanAccessor.count);
35659
+ }
35660
+ var blendShape = new BlendShape(name);
35661
+ blendShape.addFrame(1.0, positions, normals, tangents);
35662
+ mesh.addBlendShape(blendShape);
35663
+ var _posAccessor_byteOffset1, _norAccessor_byteOffset1, _tanAccessor_byteOffset1;
35664
+ 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));
35665
+ });
35666
+ promises.push(promise);
35667
+ };
35668
+ var blendShapeNames = glTFMesh.extras ? glTFMesh.extras.targetNames : null;
35669
+ var promises = new Array();
35670
+ for(var i = 0, n = glTFTargets.length; i < n; i++)_loop(i);
35671
+ return Promise.all(promises);
35559
35672
  };
35560
35673
  return GLTFMeshParser;
35561
35674
  }(GLTFParser);
@@ -35705,52 +35818,58 @@
35705
35818
  _inherits(GLTFSkinParser, GLTFParser);
35706
35819
  var _proto = GLTFSkinParser.prototype;
35707
35820
  _proto.parse = function parse(context) {
35708
- var glTFResource = context.glTFResource, glTF = context.glTF;
35709
- context.buffers;
35710
- var entities = glTFResource.entities;
35711
- var gltfSkins = glTF.skins;
35712
- if (!gltfSkins) return;
35713
- var count = gltfSkins.length;
35714
- var skins = new Array(count);
35715
- for(var i = 0; i < count; i++){
35821
+ var _loop = function _loop(i) {
35716
35822
  var _gltfSkins_i = gltfSkins[i], inverseBindMatrices = _gltfSkins_i.inverseBindMatrices, skeleton = _gltfSkins_i.skeleton, joints = _gltfSkins_i.joints, _gltfSkins_i_name = _gltfSkins_i.name, name = _gltfSkins_i_name === void 0 ? "SKIN_" + i : _gltfSkins_i_name;
35717
35823
  var jointCount = joints.length;
35718
35824
  var skin = new Skin(name);
35719
35825
  skin.inverseBindMatrices.length = jointCount;
35720
35826
  // parse IBM
35721
35827
  var accessor = glTF.accessors[inverseBindMatrices];
35722
- var buffer = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).data;
35723
- for(var i1 = 0; i1 < jointCount; i1++){
35724
- var inverseBindMatrix = new Matrix();
35725
- inverseBindMatrix.copyFromArray(buffer, i1 * 16);
35726
- skin.inverseBindMatrices[i1] = inverseBindMatrix;
35727
- }
35728
- // get joints
35729
- for(var i2 = 0; i2 < jointCount; i2++){
35730
- var jointIndex = joints[i2];
35731
- var jointName = entities[jointIndex].name;
35732
- skin.joints[i2] = jointName;
35733
- // @todo Temporary solution, but it can alleviate the current BUG, and the skinning data mechanism of SkinnedMeshRenderer will be completely refactored in the future
35734
- for(var j = entities.length - 1; j >= 0; j--){
35735
- if (jointIndex !== j && entities[j].name === jointName) {
35736
- entities[j].name = jointName + "_" + j;
35828
+ var promise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
35829
+ var buffer = bufferInfo.data;
35830
+ for(var _$i = 0; _$i < jointCount; _$i++){
35831
+ var inverseBindMatrix = new Matrix();
35832
+ inverseBindMatrix.copyFromArray(buffer, _$i * 16);
35833
+ skin.inverseBindMatrices[_$i] = inverseBindMatrix;
35834
+ // get joints
35835
+ for(var i1 = 0; i1 < jointCount; i1++){
35836
+ var jointIndex = joints[i1];
35837
+ var jointName = entities[jointIndex].name;
35838
+ skin.joints[i1] = jointName;
35839
+ // @todo Temporary solution, but it can alleviate the current BUG, and the skinning data mechanism of SkinnedMeshRenderer will be completely refactored in the future
35840
+ for(var j = entities.length - 1; j >= 0; j--){
35841
+ if (jointIndex !== j && entities[j].name === jointName) {
35842
+ entities[j].name = jointName + "_" + j;
35843
+ }
35844
+ }
35845
+ }
35846
+ // get skeleton
35847
+ if (skeleton !== undefined) {
35848
+ skin.skeleton = entities[skeleton].name;
35849
+ } else {
35850
+ var rootBone = _this._findSkeletonRootBone(joints, entities);
35851
+ if (rootBone) {
35852
+ skin.skeleton = rootBone.name;
35853
+ } else {
35854
+ throw "Failed to find skeleton root bone.";
35855
+ }
35737
35856
  }
35738
35857
  }
35739
- }
35740
- // get skeleton
35741
- if (skeleton !== undefined) {
35742
- skin.skeleton = entities[skeleton].name;
35743
- } else {
35744
- var rootBone = this._findSkeletonRootBone(joints, entities);
35745
- if (rootBone) {
35746
- skin.skeleton = rootBone.name;
35747
- } else {
35748
- throw "Failed to find skeleton root bone.";
35749
- }
35750
- }
35751
- skins[i] = skin;
35752
- }
35753
- glTFResource.skins = skins;
35858
+ return skin;
35859
+ });
35860
+ promises.push(promise);
35861
+ };
35862
+ var _this = this;
35863
+ var glTFResource = context.glTFResource, glTF = context.glTF;
35864
+ var entities = glTFResource.entities;
35865
+ var gltfSkins = glTF.skins;
35866
+ if (!gltfSkins) return;
35867
+ var count = gltfSkins.length;
35868
+ var promises = new Array();
35869
+ for(var i = 0; i < count; i++)_loop(i);
35870
+ return AssetPromise.all(promises).then(function(skins) {
35871
+ glTFResource.skins = skins;
35872
+ });
35754
35873
  };
35755
35874
  _proto._findSkeletonRootBone = function _findSkeletonRootBone(joints, entities) {
35756
35875
  var paths = {};
@@ -35790,13 +35909,14 @@
35790
35909
  var _proto = GLTFTextureParser.prototype;
35791
35910
  _proto.parse = function parse(context) {
35792
35911
  var _this = this;
35793
- var glTFResource = context.glTFResource, glTF = context.glTF, buffers = context.buffers;
35912
+ var glTFResource = context.glTFResource, glTF = context.glTF;
35794
35913
  var engine = glTFResource.engine, url = glTFResource.url;
35795
35914
  if (glTF.textures) {
35796
35915
  var texturesPromiseInfo = context.texturesPromiseInfo;
35797
35916
  AssetPromise.all(glTF.textures.map(function(param, index) {
35798
35917
  var sampler = param.sampler, _param_source = param.source, source = _param_source === void 0 ? 0 : _param_source, textureName = param.name;
35799
35918
  var _glTF_images_source = glTF.images[source], uri = _glTF_images_source.uri, bufferViewIndex = _glTF_images_source.bufferView, mimeType = _glTF_images_source.mimeType, imageName = _glTF_images_source.name;
35919
+ var samplerInfo = sampler !== undefined && _this._getSamplerInfo(glTF.samplers[sampler]);
35800
35920
  if (uri) {
35801
35921
  // TODO: support ktx extension https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_basisu/README.md
35802
35922
  var index1 = uri.lastIndexOf(".");
@@ -35804,31 +35924,36 @@
35804
35924
  var type = ext.startsWith("ktx") ? exports.AssetType.KTX : exports.AssetType.Texture2D;
35805
35925
  return engine.resourceManager.load({
35806
35926
  url: Utils.resolveAbsoluteUrl(url, uri),
35807
- type: type
35927
+ type: type,
35928
+ params: {
35929
+ mipmap: samplerInfo == null ? void 0 : samplerInfo.mipmap
35930
+ }
35808
35931
  }).then(function(texture) {
35809
35932
  if (!texture.name) {
35810
35933
  texture.name = textureName || imageName || "texture_" + index1;
35811
35934
  }
35812
35935
  if (sampler !== undefined) {
35813
- _this._parseSampler(texture, glTF.samplers[sampler]);
35936
+ _this._parseSampler(texture, samplerInfo);
35814
35937
  }
35815
35938
  return texture;
35816
35939
  });
35817
35940
  } else {
35818
35941
  var bufferView = glTF.bufferViews[bufferViewIndex];
35819
- var buffer = buffers[bufferView.buffer];
35820
- var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
35821
- return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
35822
- var texture = new Texture2D(engine, image.width, image.height);
35823
- texture.setImageSource(image);
35824
- texture.generateMipmaps();
35825
- texture.name = textureName || imageName || "texture_" + index;
35826
- if (sampler !== undefined) {
35827
- _this._parseSampler(texture, glTF.samplers[sampler]);
35828
- }
35829
- var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
35830
- context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
35831
- return texture;
35942
+ return context.getBuffers().then(function(buffers) {
35943
+ var buffer = buffers[bufferView.buffer];
35944
+ var imageBuffer = new Uint8Array(buffer, bufferView.byteOffset, bufferView.byteLength);
35945
+ return GLTFUtils.loadImageBuffer(imageBuffer, mimeType).then(function(image) {
35946
+ var texture = new Texture2D(engine, image.width, image.height, undefined, samplerInfo == null ? void 0 : samplerInfo.mipmap);
35947
+ texture.setImageSource(image);
35948
+ texture.generateMipmaps();
35949
+ texture.name = textureName || imageName || "texture_" + index;
35950
+ if (sampler !== undefined) {
35951
+ _this._parseSampler(texture, samplerInfo);
35952
+ }
35953
+ var bufferTextureRestoreInfo = new BufferTextureRestoreInfo(texture, bufferView, mimeType);
35954
+ context.contentRestorer.bufferTextures.push(bufferTextureRestoreInfo);
35955
+ return texture;
35956
+ });
35832
35957
  });
35833
35958
  }
35834
35959
  })).then(function(textures) {
@@ -35838,22 +35963,39 @@
35838
35963
  return texturesPromiseInfo.promise;
35839
35964
  }
35840
35965
  };
35841
- _proto._parseSampler = function _parseSampler(texture, sampler) {
35842
- var magFilter = sampler.magFilter, minFilter = sampler.minFilter, wrapS = sampler.wrapS, wrapT = sampler.wrapT;
35843
- if (magFilter || minFilter) {
35966
+ _proto._getSamplerInfo = function _getSamplerInfo(sampler) {
35967
+ var minFilter = sampler.minFilter, magFilter = sampler.magFilter, wrapS = sampler.wrapS, wrapT = sampler.wrapT;
35968
+ var info = {};
35969
+ if (minFilter || magFilter) {
35970
+ info.mipmap = minFilter >= TextureMinFilter.NEAREST_MIPMAP_NEAREST;
35844
35971
  if (magFilter === TextureMagFilter.NEAREST) {
35845
- texture.filterMode = exports.TextureFilterMode.Point;
35846
- } else if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
35847
- texture.filterMode = exports.TextureFilterMode.Bilinear;
35972
+ info.filterMode = exports.TextureFilterMode.Point;
35848
35973
  } else {
35849
- texture.filterMode = exports.TextureFilterMode.Trilinear;
35974
+ if (minFilter <= TextureMinFilter.LINEAR_MIPMAP_NEAREST) {
35975
+ info.filterMode = exports.TextureFilterMode.Bilinear;
35976
+ } else {
35977
+ info.filterMode = exports.TextureFilterMode.Trilinear;
35978
+ }
35850
35979
  }
35851
35980
  }
35852
35981
  if (wrapS) {
35853
- texture.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
35982
+ info.wrapModeU = GLTFTextureParser._wrapMap[wrapS];
35854
35983
  }
35855
35984
  if (wrapT) {
35856
- texture.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
35985
+ info.wrapModeV = GLTFTextureParser._wrapMap[wrapT];
35986
+ }
35987
+ return info;
35988
+ };
35989
+ _proto._parseSampler = function _parseSampler(texture, samplerInfo) {
35990
+ var filterMode = samplerInfo.filterMode, wrapModeU = samplerInfo.wrapModeU, wrapModeV = samplerInfo.wrapModeV;
35991
+ if (filterMode !== undefined) {
35992
+ texture.filterMode = filterMode;
35993
+ }
35994
+ if (wrapModeU !== undefined) {
35995
+ texture.wrapModeU = wrapModeU;
35996
+ }
35997
+ if (wrapModeV !== undefined) {
35998
+ texture.wrapModeV = wrapModeV;
35857
35999
  }
35858
36000
  };
35859
36001
  return GLTFTextureParser;
@@ -35986,7 +36128,7 @@
35986
36128
  resourceManager.addContentRestorer(restorer);
35987
36129
  masterPromiseInfo.resolve(glTFResource);
35988
36130
  }).catch(function(e) {
35989
- var msg = "Error loading glTF model from " + url + " .";
36131
+ var msg = "Error loading glTF model from " + url + " : " + e;
35990
36132
  Logger.error(msg);
35991
36133
  masterPromiseInfo.reject(msg);
35992
36134
  context.defaultSceneRootPromiseInfo.reject(e);
@@ -37907,7 +38049,7 @@
37907
38049
  _this.request(item.url, _extends({}, item, {
37908
38050
  type: "arraybuffer"
37909
38051
  })).then(function(data) {
37910
- return decode(data, resourceManager.engine);
38052
+ return decode(data, resourceManager.engine).then(resolve);
37911
38053
  }).catch(reject);
37912
38054
  });
37913
38055
  };
@@ -38044,7 +38186,7 @@
38044
38186
  };
38045
38187
  _proto.createAndParse = function createAndParse(context, schema, glTFPrimitive, glTFMesh) {
38046
38188
  var _this = this;
38047
- var glTF = context.glTF, buffers = context.buffers, engine = context.glTFResource.engine;
38189
+ var glTF = context.glTF, engine = context.glTFResource.engine;
38048
38190
  var bufferViews = glTF.bufferViews, accessors = glTF.accessors;
38049
38191
  var bufferViewIndex = schema.bufferView, gltfAttributeMap = schema.attributes;
38050
38192
  var attributeMap = {};
@@ -38066,21 +38208,23 @@
38066
38208
  useUniqueIDs: true,
38067
38209
  indexType: indexType
38068
38210
  };
38069
- var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
38070
- return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
38071
- var mesh = new ModelMesh(engine, glTFMesh.name);
38072
- return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
38073
- for(var j = 0; j < decodedGeometry.attributes.length; j++){
38074
- if (decodedGeometry.attributes[j].name === attributeSemantic) {
38075
- return decodedGeometry.attributes[j].array;
38211
+ return context.getBuffers().then(function(buffers) {
38212
+ var buffer = GLTFUtils.getBufferViewData(bufferViews[bufferViewIndex], buffers);
38213
+ return KHR_draco_mesh_compression._decoder.decode(buffer, taskConfig).then(function(decodedGeometry) {
38214
+ var mesh = new ModelMesh(engine, glTFMesh.name);
38215
+ return _this._parseMeshFromGLTFPrimitiveDraco(mesh, glTFMesh, glTFPrimitive, glTF, function(attributeSemantic) {
38216
+ for(var j = 0; j < decodedGeometry.attributes.length; j++){
38217
+ if (decodedGeometry.attributes[j].name === attributeSemantic) {
38218
+ return decodedGeometry.attributes[j].array;
38219
+ }
38076
38220
  }
38077
- }
38078
- return null;
38079
- }, function(attributeSemantic, shapeIndex) {
38080
- throw "BlendShape animation is not supported when using draco.";
38081
- }, function() {
38082
- return decodedGeometry.index.array;
38083
- }, context.keepMeshData);
38221
+ return null;
38222
+ }, function(attributeSemantic, shapeIndex) {
38223
+ throw "BlendShape animation is not supported when using draco.";
38224
+ }, function() {
38225
+ return decodedGeometry.index.array;
38226
+ }, context.keepMeshData);
38227
+ });
38084
38228
  });
38085
38229
  };
38086
38230
  _proto._parseMeshFromGLTFPrimitiveDraco = function _parseMeshFromGLTFPrimitiveDraco(mesh, gltfMesh, gltfPrimitive, gltf, getVertexBufferData, getBlendShapeData, getIndexBufferData, keepMeshData) {
@@ -38179,7 +38323,7 @@
38179
38323
  mesh.addSubMesh(0, vertexCount, mode);
38180
38324
  }
38181
38325
  // BlendShapes
38182
- targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, targets, getBlendShapeData);
38326
+ targets && GLTFMeshParser._createBlendShape(mesh, null, gltfMesh, accessors, targets, getBlendShapeData);
38183
38327
  mesh.uploadData(!keepMeshData);
38184
38328
  return Promise.resolve(mesh);
38185
38329
  };
@@ -38405,7 +38549,7 @@
38405
38549
  ], GALACEAN_animation_event);
38406
38550
 
38407
38551
  //@ts-ignore
38408
- var version = "1.0.0-beta.16";
38552
+ var version = "1.0.0-beta.18";
38409
38553
  console.log("Galacean engine version: " + version);
38410
38554
  for(var key in CoreObjects){
38411
38555
  Loader.registerClass(key, CoreObjects[key]);