@galacean/engine 0.0.0-experimental-shaderlab.2 → 0.0.0-experimental-stateMachine.0

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
@@ -9794,7 +9794,8 @@
9794
9794
  }
9795
9795
  var shaderInfo = Shader._shaderLab.parseShader(nameOrShaderSource);
9796
9796
  if (shaderMap[shaderInfo.name]) {
9797
- throw 'Shader named "' + shaderInfo.name + '" already exists.';
9797
+ console.error('Shader named "' + shaderInfo.name + '" already exists.');
9798
+ return;
9798
9799
  }
9799
9800
  var subShaderList = shaderInfo.subShaders.map(function(subShaderInfo) {
9800
9801
  var passList = subShaderInfo.passes.map(function(passInfo) {
@@ -9833,7 +9834,8 @@
9833
9834
  return shader;
9834
9835
  } else {
9835
9836
  if (shaderMap[nameOrShaderSource]) {
9836
- throw 'Shader named "' + nameOrShaderSource + '" already exists.';
9837
+ console.error('Shader named "' + nameOrShaderSource + '" already exists.');
9838
+ return;
9837
9839
  }
9838
9840
  if (typeof vertexSourceOrShaderPassesOrSubShaders === "string") {
9839
9841
  var shaderPass = new ShaderPass(vertexSourceOrShaderPassesOrSubShaders, fragmentSource);
@@ -20852,8 +20854,6 @@
20852
20854
  AssetType[/** 2D Texture. */ "Texture2D"] = "Texture2D";
20853
20855
  AssetType[/** Cube Texture. */ "TextureCube"] = "TextureCube";
20854
20856
  AssetType[/** Material. */ "Material"] = "Material";
20855
- AssetType[/** Shader */ "Shader"] = "Shader";
20856
- AssetType[/** Shader Chunk */ "ShaderChunk"] = "ShaderChunk";
20857
20857
  AssetType[/** Mesh. */ "Mesh"] = "Mesh";
20858
20858
  AssetType[/** AnimationClip. */ "AnimationClip"] = "AnimationClip";
20859
20859
  AssetType[/** AnimatorController. */ "AnimatorController"] = "AnimatorController";
@@ -26804,9 +26804,10 @@
26804
26804
  */ _proto._updateShaderData = function _updateShaderData(shaderData) {
26805
26805
  var _this = this, spotLight = _this._spotLights, pointLight = _this._pointLights, directLight = _this._directLights;
26806
26806
  var _this1 = this, spotData = _this1._spotData, pointData = _this1._pointData, directData = _this1._directData;
26807
- var spotLightCount = spotLight.length;
26808
- var pointLightCount = pointLight.length;
26809
- var directLightCount = directLight.length;
26807
+ var maxLight = LightManager._maxLight;
26808
+ var spotLightCount = Math.min(spotLight.length, maxLight);
26809
+ var pointLightCount = Math.min(pointLight.length, maxLight);
26810
+ var directLightCount = Math.min(directLight.length, maxLight);
26810
26811
  for(var i = 0; i < spotLightCount; i++){
26811
26812
  spotLight.get(i)._appendData(i, spotData);
26812
26813
  }
@@ -31574,13 +31575,69 @@
31574
31575
  _proto.dispose = function dispose() {};
31575
31576
  return AnimationEventHandler;
31576
31577
  }();
31578
+ /**
31579
+ * Condition that is used to determine if a transition must be taken.
31580
+ */ var AnimatorCondition = function AnimatorCondition() {};
31577
31581
  /**
31578
31582
  * Transitions define when and how the state machine switch from on state to another. AnimatorTransition always originate from a StateMachine or a StateMachine entry.
31579
- */ var AnimatorStateTransition = function AnimatorStateTransition() {
31580
- /** The duration of the transition. This is represented in normalized time. */ this.duration = 0;
31581
- /** The time at which the destination state will start. This is represented in normalized time. */ this.offset = 0;
31582
- /** ExitTime represents the exact time at which the transition can take effect. This is represented in normalized time. */ this.exitTime = 1;
31583
- };
31583
+ */ var AnimatorStateTransition = /*#__PURE__*/ function() {
31584
+ var AnimatorStateTransition = function AnimatorStateTransition() {
31585
+ /** The duration of the transition. This is represented in normalized time. */ this.duration = 0;
31586
+ /** The time at which the destination state will start. This is represented in normalized time. */ this.offset = 0;
31587
+ /** ExitTime represents the exact time at which the transition can take effect. This is represented in normalized time. */ this.exitTime = 1;
31588
+ /** Mutes the transition. The transition will never occur. */ this.mute = false;
31589
+ /** Is the transition destination the exit of the current state machine. */ this.isExit = false;
31590
+ this._conditions = [];
31591
+ this._solo = false;
31592
+ };
31593
+ var _proto = AnimatorStateTransition.prototype;
31594
+ _proto.addCondition = function addCondition(param, parameter, threshold) {
31595
+ if (typeof param === "object") {
31596
+ this._conditions.push(param);
31597
+ return param;
31598
+ } else {
31599
+ var condition = new AnimatorCondition();
31600
+ condition.mode = param;
31601
+ condition.parameter = parameter;
31602
+ condition.threshold = threshold;
31603
+ this._conditions.push(condition);
31604
+ return condition;
31605
+ }
31606
+ };
31607
+ /**
31608
+ * Remove a condition from the transition.
31609
+ * @param condition - The condition to remove
31610
+ */ _proto.removeCondition = function removeCondition(condition) {
31611
+ var index = this._conditions.indexOf(condition);
31612
+ index !== -1 && this._conditions.splice(index, 1);
31613
+ };
31614
+ _create_class$2(AnimatorStateTransition, [
31615
+ {
31616
+ key: "solo",
31617
+ get: /** Mutes all other transitions in the source state. */ function get() {
31618
+ return this._solo;
31619
+ },
31620
+ set: function set(value) {
31621
+ if (this._solo === value) return;
31622
+ this._solo = value;
31623
+ if (value) {
31624
+ this._srcState && this._srcState._updateSoloTransition(true);
31625
+ } else {
31626
+ this._srcState && this._srcState._updateSoloTransition();
31627
+ }
31628
+ }
31629
+ },
31630
+ {
31631
+ key: "conditions",
31632
+ get: /**
31633
+ * The conditions in the transition.
31634
+ */ function get() {
31635
+ return this._conditions;
31636
+ }
31637
+ }
31638
+ ]);
31639
+ return AnimatorStateTransition;
31640
+ }();
31584
31641
  /**
31585
31642
  * Animation wrap mode.
31586
31643
  */ exports.WrapMode = void 0;
@@ -31652,6 +31709,15 @@
31652
31709
  this.curveLayerOwner = [];
31653
31710
  this.eventHandlers = [];
31654
31711
  };
31712
+ exports.AnimatorConditionMode = void 0;
31713
+ (function(AnimatorConditionMode) {
31714
+ AnimatorConditionMode[AnimatorConditionMode["If"] = 0] = "If";
31715
+ AnimatorConditionMode[AnimatorConditionMode["IfNot"] = 1] = "IfNot";
31716
+ AnimatorConditionMode[AnimatorConditionMode["Greater"] = 2] = "Greater";
31717
+ AnimatorConditionMode[AnimatorConditionMode["Less"] = 3] = "Less";
31718
+ AnimatorConditionMode[AnimatorConditionMode["Equals"] = 4] = "Equals";
31719
+ AnimatorConditionMode[AnimatorConditionMode["NotEquals"] = 5] = "NotEquals";
31720
+ })(exports.AnimatorConditionMode || (exports.AnimatorConditionMode = {}));
31655
31721
  /**
31656
31722
  * The controller of the animation system.
31657
31723
  */ var Animator = /*#__PURE__*/ function(Component1) {
@@ -31704,26 +31770,29 @@
31704
31770
  animatorLayerData.srcPlayData.reset(state, animatorStateData, state._getDuration() * normalizedTimeOffset);
31705
31771
  this.update(0);
31706
31772
  };
31707
- /**
31708
- * Create a cross fade from the current state to another state.
31709
- * @param stateName - The state name
31710
- * @param normalizedTransitionDuration - The duration of the transition (normalized)
31711
- * @param layerIndex - The layer index(default -1). If layer is -1, play the first state with the given state name
31712
- * @param normalizedTimeOffset - The time offset between 0 and 1(default 0)
31713
- */ _proto.crossFade = function crossFade(stateName, normalizedTransitionDuration, layerIndex, normalizedTimeOffset) {
31773
+ _proto.crossFade = function crossFade(stateNameOrTransition, normalizedTransitionDurationOrLayerIndex, layerIndex, normalizedTimeOffset) {
31714
31774
  if (layerIndex === void 0) layerIndex = -1;
31715
31775
  if (normalizedTimeOffset === void 0) normalizedTimeOffset = 0;
31716
- var _this__controllerUpdateFlag;
31717
- if ((_this__controllerUpdateFlag = this._controllerUpdateFlag) == null ? void 0 : _this__controllerUpdateFlag.flag) {
31718
- this._reset();
31776
+ var state;
31777
+ var playLayerIndex;
31778
+ var normalizedTransitionDuration;
31779
+ var transition;
31780
+ if (typeof stateNameOrTransition === "string") {
31781
+ var info = this._getAnimatorStateInfo(stateNameOrTransition, layerIndex);
31782
+ state = info.state;
31783
+ playLayerIndex = info.layerIndex;
31784
+ normalizedTransitionDuration = normalizedTransitionDurationOrLayerIndex;
31785
+ var manuallyTransition = this._getAnimatorLayerData(playLayerIndex).manuallyTransition;
31786
+ manuallyTransition.duration = normalizedTransitionDuration;
31787
+ manuallyTransition.offset = normalizedTimeOffset;
31788
+ manuallyTransition.destinationState = state;
31789
+ transition = manuallyTransition;
31790
+ } else {
31791
+ state = stateNameOrTransition.destinationState;
31792
+ playLayerIndex = normalizedTransitionDurationOrLayerIndex != null ? normalizedTransitionDurationOrLayerIndex : this._getAnimatorStateInfo(state.name, playLayerIndex).layerIndex;
31793
+ transition = stateNameOrTransition;
31719
31794
  }
31720
- this._playFrameCount = this.engine.time.frameCount;
31721
- var _this__getAnimatorStateInfo = this._getAnimatorStateInfo(stateName, layerIndex), state = _this__getAnimatorStateInfo.state, playLayerIndex = _this__getAnimatorStateInfo.layerIndex;
31722
- var manuallyTransition = this._getAnimatorLayerData(playLayerIndex).manuallyTransition;
31723
- manuallyTransition.duration = normalizedTransitionDuration;
31724
- manuallyTransition.offset = normalizedTimeOffset;
31725
- manuallyTransition.destinationState = state;
31726
- if (this._crossFadeByTransition(manuallyTransition, playLayerIndex)) {
31795
+ if (this._crossFadeByTransition(transition, playLayerIndex)) {
31727
31796
  this.update(0);
31728
31797
  }
31729
31798
  };
@@ -31750,7 +31819,7 @@
31750
31819
  return;
31751
31820
  }
31752
31821
  if ((_this__controllerUpdateFlag = this._controllerUpdateFlag) == null ? void 0 : _this__controllerUpdateFlag.flag) {
31753
- this._checkAutoPlay();
31822
+ this._checkEntryState();
31754
31823
  return;
31755
31824
  }
31756
31825
  this._updateMark++;
@@ -31778,9 +31847,31 @@
31778
31847
  return this._getAnimatorStateInfo(stateName, layerIndex).state;
31779
31848
  };
31780
31849
  /**
31850
+ * Get the layer by name.
31851
+ * @param name - The layer's name.
31852
+ */ _proto.findLayerByName = function findLayerByName(name1) {
31853
+ return this._animatorController._layersMap[name1];
31854
+ };
31855
+ /**
31856
+ * Get the parameter by name.
31857
+ * @param name - The name of the parameter
31858
+ */ _proto.getParameter = function getParameter(name1) {
31859
+ return this._animatorController._parametersMap[name1] || null;
31860
+ };
31861
+ /**
31862
+ * Set the value of the given parameter.
31863
+ * @param name - The name of the parameter
31864
+ */ _proto.setParameter = function setParameter(name1, value) {
31865
+ var controller = this._animatorController;
31866
+ var parameter = controller._parametersMap[name1];
31867
+ if (parameter) {
31868
+ parameter.value = value;
31869
+ }
31870
+ };
31871
+ /**
31781
31872
  * @internal
31782
31873
  */ _proto._onEnable = function _onEnable() {
31783
- this.animatorController && this._checkAutoPlay();
31874
+ this.animatorController && this._checkEntryState();
31784
31875
  this._entity.getComponentsIncludeChildren(exports.Renderer, this._controlledRenderers);
31785
31876
  };
31786
31877
  /**
@@ -31854,20 +31945,19 @@
31854
31945
  var relativePath = curve.relativePath;
31855
31946
  var targetEntity = curve.relativePath === "" ? entity : entity.findByPath(curve.relativePath);
31856
31947
  if (targetEntity) {
31857
- var _curveOwnerPool, _instanceId, _propertyOwners, _property, _layerCurveOwnerPool, _instanceId1, _layerPropertyOwners, _propertyPath;
31858
- var propertyPath = "" + curve.typeIndex + "." + curve.property;
31948
+ var _curveOwnerPool, _instanceId, _propertyOwners, _property, _layerCurveOwnerPool, _instanceId1, _layerPropertyOwners, _property1;
31859
31949
  var component = curve.typeIndex > 0 ? targetEntity.getComponents(curve.type, AnimationCurveOwner._components)[curve.typeIndex] : targetEntity.getComponent(curve.type);
31860
31950
  if (!component) {
31861
31951
  continue;
31862
31952
  }
31863
31953
  var property = curve.property;
31864
- var instanceId = targetEntity.instanceId;
31954
+ var instanceId = component.instanceId;
31865
31955
  // Get owner
31866
31956
  var propertyOwners = (_curveOwnerPool = curveOwnerPool)[_instanceId = instanceId] || (_curveOwnerPool[_instanceId] = Object.create(null));
31867
31957
  var owner = (_propertyOwners = propertyOwners)[_property = property] || (_propertyOwners[_property] = curve._createCurveOwner(targetEntity, component));
31868
31958
  // Get layer owner
31869
31959
  var layerPropertyOwners = (_layerCurveOwnerPool = layerCurveOwnerPool)[_instanceId1 = instanceId] || (_layerCurveOwnerPool[_instanceId1] = Object.create(null));
31870
- var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_propertyPath = propertyPath] || (_layerPropertyOwners[_propertyPath] = curve._createCurveLayerOwner(owner));
31960
+ var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_property1 = property] || (_layerPropertyOwners[_property1] = curve._createCurveLayerOwner(owner));
31871
31961
  if (mask && mask.pathMasks.length) {
31872
31962
  var _mask_getPathMask;
31873
31963
  var _mask_getPathMask_active;
@@ -31972,7 +32062,8 @@
31972
32062
  return animatorLayerData;
31973
32063
  };
31974
32064
  _proto._updateLayer = function _updateLayer(layerIndex, firstLayer, deltaTime, aniUpdate) {
31975
- var _this__animatorController_layers_layerIndex = this._animatorController.layers[layerIndex], blendingMode = _this__animatorController_layers_layerIndex.blendingMode, weight = _this__animatorController_layers_layerIndex.weight;
32065
+ var _this__animatorController_layers_layerIndex = this._animatorController.layers[layerIndex], blendingMode = _this__animatorController_layers_layerIndex.blendingMode, weight = _this__animatorController_layers_layerIndex.weight, stateMachine = _this__animatorController_layers_layerIndex.stateMachine;
32066
+ if (!stateMachine) return;
31976
32067
  var layerData = this._animatorLayersData[layerIndex];
31977
32068
  var srcPlayData = layerData.srcPlayData, destPlayData = layerData.destPlayData;
31978
32069
  var additive = blendingMode === exports.AnimatorLayerBlendingMode.Additive;
@@ -31997,6 +32088,7 @@
31997
32088
  var state = playData.state, lastPlayState = playData.playState, lastClipTime = playData.clipTime;
31998
32089
  var transitions = state.transitions;
31999
32090
  var _state_clip = state.clip, curveBindings = _state_clip._curveBindings;
32091
+ var anyStateTransitions = this.layers[layerIndex].stateMachine.anyStateTransitions;
32000
32092
  var speed = state.speed * this.speed;
32001
32093
  playData.frameTime += speed * delta;
32002
32094
  playData.update(speed < 0);
@@ -32029,10 +32121,10 @@
32029
32121
  } else {
32030
32122
  this._callAnimatorScriptOnUpdate(state, layerIndex);
32031
32123
  }
32032
- if (transitions.length) {
32124
+ if (transitions.length || anyStateTransitions.length) {
32033
32125
  var layerState = layerData.layerState;
32034
32126
  if (layerState !== LayerState.CrossFading && layerState !== LayerState.FixedCrossFading) {
32035
- this._checkTransition(playData, transitions, layerIndex, lastClipTime, clipTime);
32127
+ this._checkTransition(playData, transitions, anyStateTransitions, layerIndex, lastClipTime, clipTime);
32036
32128
  }
32037
32129
  }
32038
32130
  };
@@ -32178,43 +32270,61 @@
32178
32270
  }
32179
32271
  }
32180
32272
  };
32181
- _proto._checkTransition = function _checkTransition(playState, transitions, layerIndex, lastClipTime, clipTime) {
32273
+ _proto._checkTransition = function _checkTransition(playState, transitions, anyStateTransitions, layerIndex, lastClipTime, clipTime) {
32182
32274
  var state = playState.state;
32183
32275
  var clipDuration = state.clip.length;
32276
+ var targetTransition = null;
32184
32277
  if (this.speed * state.speed >= 0) {
32185
32278
  if (clipTime < lastClipTime) {
32186
- this._checkSubTransition(playState, transitions, layerIndex, lastClipTime, state.clipEndTime * clipDuration);
32187
- playState.currentTransitionIndex = 0;
32188
- this._checkSubTransition(playState, transitions, layerIndex, state.clipStartTime * clipDuration, clipTime);
32279
+ targetTransition = this._checkSubTransition(playState, transitions, layerIndex, lastClipTime, state.clipEndTime * clipDuration);
32280
+ if (!targetTransition) {
32281
+ playState.currentTransitionIndex = 0;
32282
+ targetTransition = this._checkSubTransition(playState, transitions, layerIndex, state.clipStartTime * clipDuration, clipTime);
32283
+ }
32189
32284
  } else {
32190
- this._checkSubTransition(playState, transitions, layerIndex, lastClipTime, clipTime);
32285
+ targetTransition = this._checkSubTransition(playState, transitions, layerIndex, lastClipTime, clipTime);
32191
32286
  }
32192
32287
  } else {
32193
32288
  if (clipTime > lastClipTime) {
32194
- this._checkBackwardsSubTransition(playState, transitions, layerIndex, lastClipTime, state.clipStartTime * clipDuration);
32195
- playState.currentTransitionIndex = transitions.length - 1;
32196
- this._checkBackwardsSubTransition(playState, transitions, layerIndex, clipTime, state.clipEndTime * clipDuration);
32289
+ targetTransition = this._checkBackwardsSubTransition(playState, transitions, layerIndex, lastClipTime, state.clipStartTime * clipDuration);
32290
+ if (!targetTransition) {
32291
+ playState.currentTransitionIndex = transitions.length - 1;
32292
+ targetTransition = this._checkBackwardsSubTransition(playState, transitions, layerIndex, clipTime, state.clipEndTime * clipDuration);
32293
+ }
32197
32294
  } else {
32198
- this._checkBackwardsSubTransition(playState, transitions, layerIndex, lastClipTime, clipTime);
32295
+ targetTransition = this._checkBackwardsSubTransition(playState, transitions, layerIndex, lastClipTime, clipTime);
32296
+ }
32297
+ }
32298
+ if (!targetTransition) {
32299
+ for(var i = 0, n = anyStateTransitions.length; i < n; ++i){
32300
+ var transition = anyStateTransitions[i];
32301
+ if (this._checkConditions(state, transition)) {
32302
+ this._crossFadeByTransition(transition, layerIndex);
32303
+ break;
32304
+ }
32199
32305
  }
32200
32306
  }
32201
32307
  };
32202
32308
  _proto._checkSubTransition = function _checkSubTransition(playState, transitions, layerIndex, lastClipTime, curClipTime) {
32309
+ var state = playState.state;
32203
32310
  var transitionIndex = playState.currentTransitionIndex;
32204
- var duration = playState.state._getDuration();
32311
+ var duration = state._getDuration();
32205
32312
  for(var n = transitions.length; transitionIndex < n; transitionIndex++){
32206
32313
  var transition = transitions[transitionIndex];
32207
32314
  var exitTime = transition.exitTime * duration;
32208
32315
  if (exitTime > curClipTime) {
32209
32316
  break;
32210
32317
  }
32211
- if (exitTime >= lastClipTime) {
32212
- this._crossFadeByTransition(transition, layerIndex);
32318
+ if (exitTime >= lastClipTime && this._checkConditions(state, transition)) {
32213
32319
  playState.currentTransitionIndex = Math.min(transitionIndex + 1, n - 1);
32320
+ this._applyTransition(transition, layerIndex);
32321
+ return transition;
32214
32322
  }
32215
32323
  }
32324
+ return null;
32216
32325
  };
32217
32326
  _proto._checkBackwardsSubTransition = function _checkBackwardsSubTransition(playState, transitions, layerIndex, lastClipTime, curClipTime) {
32327
+ var state = playState.state;
32218
32328
  var transitionIndex = playState.currentTransitionIndex;
32219
32329
  var duration = playState.state._getDuration();
32220
32330
  for(; transitionIndex >= 0; transitionIndex--){
@@ -32223,14 +32333,76 @@
32223
32333
  if (exitTime < curClipTime) {
32224
32334
  break;
32225
32335
  }
32226
- if (exitTime <= lastClipTime) {
32227
- this._crossFadeByTransition(transition, layerIndex);
32336
+ if (exitTime <= lastClipTime && this._checkConditions(state, transition)) {
32228
32337
  playState.currentTransitionIndex = Math.max(transitionIndex - 1, 0);
32338
+ this._applyTransition(transition, layerIndex);
32339
+ return transition;
32229
32340
  }
32230
32341
  }
32342
+ return null;
32343
+ };
32344
+ _proto._applyTransition = function _applyTransition(transition, layerIndex) {
32345
+ if (transition.isExit) {
32346
+ this._checkEntryState();
32347
+ return;
32348
+ }
32349
+ this._crossFadeByTransition(transition, layerIndex);
32350
+ };
32351
+ _proto._checkConditions = function _checkConditions(state, transition) {
32352
+ var mute = transition.mute, conditions = transition.conditions, solo = transition.solo;
32353
+ if (mute) return false;
32354
+ if (state && state._hasSoloTransition && !solo) return false;
32355
+ var allPass = true;
32356
+ for(var i = 0, n = conditions.length; i < n; ++i){
32357
+ var pass = false;
32358
+ var _conditions_i = conditions[i], mode = _conditions_i.mode, name1 = _conditions_i.parameter, threshold = _conditions_i.threshold;
32359
+ var parameter = this.getParameter(name1);
32360
+ switch(mode){
32361
+ case exports.AnimatorConditionMode.Equals:
32362
+ if (parameter.value === threshold) {
32363
+ pass = true;
32364
+ }
32365
+ break;
32366
+ case exports.AnimatorConditionMode.Greater:
32367
+ if (parameter.value > threshold) {
32368
+ pass = true;
32369
+ }
32370
+ break;
32371
+ case exports.AnimatorConditionMode.Less:
32372
+ if (parameter.value < threshold) {
32373
+ pass = true;
32374
+ }
32375
+ break;
32376
+ case exports.AnimatorConditionMode.NotEquals:
32377
+ if (parameter.value !== threshold) {
32378
+ pass = true;
32379
+ }
32380
+ break;
32381
+ case exports.AnimatorConditionMode.If:
32382
+ if (parameter.value === true) {
32383
+ pass = true;
32384
+ }
32385
+ break;
32386
+ case exports.AnimatorConditionMode.IfNot:
32387
+ if (parameter.value === false) {
32388
+ pass = true;
32389
+ }
32390
+ break;
32391
+ }
32392
+ if (!pass) {
32393
+ allPass = false;
32394
+ break;
32395
+ }
32396
+ }
32397
+ return allPass;
32231
32398
  };
32232
32399
  _proto._crossFadeByTransition = function _crossFadeByTransition(transition, layerIndex) {
32400
+ var _this__controllerUpdateFlag;
32233
32401
  var crossState = transition.destinationState;
32402
+ if ((_this__controllerUpdateFlag = this._controllerUpdateFlag) == null ? void 0 : _this__controllerUpdateFlag.flag) {
32403
+ this._reset();
32404
+ }
32405
+ this._playFrameCount = this.engine.time.frameCount;
32234
32406
  if (!crossState) {
32235
32407
  return false;
32236
32408
  }
@@ -32341,13 +32513,24 @@
32341
32513
  scripts[i].onStateExit(this, state, layerIndex);
32342
32514
  }
32343
32515
  };
32344
- _proto._checkAutoPlay = function _checkAutoPlay() {
32516
+ _proto._checkEntryState = function _checkEntryState() {
32345
32517
  var layers = this._animatorController.layers;
32346
32518
  for(var i = 0, n = layers.length; i < n; ++i){
32347
- var _stateMachine;
32348
32519
  var stateMachine = layers[i].stateMachine;
32349
- if ((_stateMachine = stateMachine) == null ? void 0 : _stateMachine.defaultState) {
32350
- this.play(stateMachine.defaultState.name, i);
32520
+ if (!stateMachine) continue;
32521
+ var entryTransitions = stateMachine._entryTransitions;
32522
+ var length = entryTransitions.length;
32523
+ if (length) {
32524
+ for(var j = 0, m = length; j < m; j++){
32525
+ var transition = entryTransitions[j];
32526
+ if (this._checkConditions(null, transition)) {
32527
+ this.crossFade(transition, i);
32528
+ break;
32529
+ }
32530
+ }
32531
+ } else {
32532
+ var defaultState = stateMachine.defaultState;
32533
+ defaultState && this.play(defaultState.name, i);
32351
32534
  }
32352
32535
  }
32353
32536
  };
@@ -32373,6 +32556,22 @@
32373
32556
  this._animatorController = animatorController;
32374
32557
  }
32375
32558
  }
32559
+ },
32560
+ {
32561
+ key: "layers",
32562
+ get: /**
32563
+ * The layers in the animator's controller.
32564
+ */ function get() {
32565
+ return this._animatorController._layers;
32566
+ }
32567
+ },
32568
+ {
32569
+ key: "parameters",
32570
+ get: /**
32571
+ * The parameters in the animator's controller.
32572
+ */ function get() {
32573
+ return this._animatorController._parameters;
32574
+ }
32376
32575
  }
32377
32576
  ]);
32378
32577
  return Animator;
@@ -32401,15 +32600,44 @@
32401
32600
  __decorate$1([
32402
32601
  ignoreClone
32403
32602
  ], Animator.prototype, "_controlledRenderers", void 0);
32603
+ /**
32604
+ * Used to communicate between scripting and the controller, parameters can be set in scripting and used by the controller.
32605
+ */ var AnimatorControllerParameter = function AnimatorControllerParameter() {};
32404
32606
  /**
32405
32607
  * Store the data for Animator playback.
32406
32608
  */ var AnimatorController = /*#__PURE__*/ function() {
32407
32609
  var AnimatorController = function AnimatorController() {
32610
+ /** @internal */ this._parameters = [];
32611
+ /** @internal */ this._parametersMap = {};
32612
+ /** @internal */ this._layers = [];
32613
+ /** @internal */ this._layersMap = {};
32408
32614
  this._updateFlagManager = new UpdateFlagManager();
32409
- this._layers = [];
32410
- this._layersMap = {};
32411
32615
  };
32412
32616
  var _proto = AnimatorController.prototype;
32617
+ _proto.addParameter = function addParameter(param, defaultValue) {
32618
+ if (typeof param === "string") {
32619
+ var parameter = new AnimatorControllerParameter();
32620
+ parameter.name = param;
32621
+ parameter.value = defaultValue;
32622
+ this._parametersMap[param] = parameter;
32623
+ this._parameters.push(parameter);
32624
+ return parameter;
32625
+ } else {
32626
+ this._parametersMap[param.name] = param;
32627
+ this._parameters.push(param);
32628
+ return param;
32629
+ }
32630
+ };
32631
+ /**
32632
+ * Remove a parameter from the controller.
32633
+ * @param parameter - The parameter
32634
+ */ _proto.removeParameter = function removeParameter(parameter) {
32635
+ var index = this._parameters.indexOf(parameter);
32636
+ if (index !== -1) {
32637
+ this._parameters.splice(index, 1);
32638
+ delete this._parametersMap[parameter.name];
32639
+ }
32640
+ };
32413
32641
  /**
32414
32642
  * Get the layer by name.
32415
32643
  * @param name - The layer's name.
@@ -32455,6 +32683,14 @@
32455
32683
  */ function get() {
32456
32684
  return this._layers;
32457
32685
  }
32686
+ },
32687
+ {
32688
+ key: "parameters",
32689
+ get: /**
32690
+ * The parameters in the controller.
32691
+ */ function get() {
32692
+ return this._parameters;
32693
+ }
32458
32694
  }
32459
32695
  ]);
32460
32696
  return AnimatorController;
@@ -32513,16 +32749,22 @@
32513
32749
  this./** @internal */ _onStateUpdateScripts = [];
32514
32750
  this./** @internal */ _onStateExitScripts = [];
32515
32751
  this./** @internal */ _updateFlagManager = new UpdateFlagManager();
32752
+ this./** @internal */ _hasSoloTransition = false;
32516
32753
  this._clipStartTime = 0;
32517
32754
  this._clipEndTime = 1;
32518
32755
  this._transitions = [];
32519
32756
  this._onClipChanged = this._onClipChanged.bind(this);
32520
32757
  };
32521
32758
  var _proto = AnimatorState.prototype;
32522
- /**
32523
- * Add an outgoing transition to the destination state.
32524
- * @param transition - The transition
32525
- */ _proto.addTransition = function addTransition(transition) {
32759
+ _proto.addTransition = function addTransition(transitionOrAnimatorState) {
32760
+ var transition;
32761
+ if (_instanceof1$2(transitionOrAnimatorState, AnimatorState)) {
32762
+ transition = new AnimatorStateTransition();
32763
+ transition.destinationState = transitionOrAnimatorState;
32764
+ } else {
32765
+ transition = transitionOrAnimatorState;
32766
+ }
32767
+ transition._srcState = this;
32526
32768
  var transitions = this._transitions;
32527
32769
  var count = transitions.length;
32528
32770
  var time = transition.exitTime;
@@ -32534,6 +32776,10 @@
32534
32776
  while(--index >= 0 && time < transitions[index].exitTime);
32535
32777
  transitions.splice(index + 1, 0, transition);
32536
32778
  }
32779
+ if (transition.solo) {
32780
+ !this._hasSoloTransition && this._updateSoloTransition(true);
32781
+ }
32782
+ return transition;
32537
32783
  };
32538
32784
  /**
32539
32785
  * Remove a transition from the state.
@@ -32541,6 +32787,7 @@
32541
32787
  */ _proto.removeTransition = function removeTransition(transition) {
32542
32788
  var index = this._transitions.indexOf(transition);
32543
32789
  index !== -1 && this._transitions.splice(index, 1);
32790
+ this._updateSoloTransition();
32544
32791
  };
32545
32792
  /**
32546
32793
  * Adds a state machine script class of type T to the AnimatorState.
@@ -32595,6 +32842,21 @@
32595
32842
  */ _proto._onClipChanged = function _onClipChanged() {
32596
32843
  this._updateFlagManager.dispatch();
32597
32844
  };
32845
+ /**
32846
+ * @internal
32847
+ */ _proto._updateSoloTransition = function _updateSoloTransition(hasSolo) {
32848
+ if (hasSolo !== undefined) {
32849
+ this._hasSoloTransition = hasSolo;
32850
+ } else {
32851
+ this._hasSoloTransition = false;
32852
+ for(var i = 0, n = this.transitions.length; i < n; ++i){
32853
+ if (this.transitions[i].solo) {
32854
+ this._hasSoloTransition = true;
32855
+ return;
32856
+ }
32857
+ }
32858
+ }
32859
+ };
32598
32860
  _create_class$2(AnimatorState, [
32599
32861
  {
32600
32862
  key: "transitions",
@@ -32625,10 +32887,26 @@
32625
32887
  clip && clip._updateFlagManager.addListener(this._onClipChanged);
32626
32888
  }
32627
32889
  },
32890
+ {
32891
+ key: "startTime",
32892
+ get: /**
32893
+ * The start time of this state's clip
32894
+ */ function get() {
32895
+ return this._clip.length * this._clipStartTime;
32896
+ }
32897
+ },
32898
+ {
32899
+ key: "endTime",
32900
+ get: /**
32901
+ * The end time of this state's clip
32902
+ */ function get() {
32903
+ return this._clip.length * this._clipEndTime;
32904
+ }
32905
+ },
32628
32906
  {
32629
32907
  key: "clipStartTime",
32630
32908
  get: /**
32631
- * The start time of the clip, the range is 0 to 1, default is 0.
32909
+ * The normalized start time of the clip, the range is 0 to 1, default is 0.
32632
32910
  */ function get() {
32633
32911
  return this._clipStartTime;
32634
32912
  },
@@ -32639,7 +32917,7 @@
32639
32917
  {
32640
32918
  key: "clipEndTime",
32641
32919
  get: /**
32642
- * The end time of the clip, the range is 0 to 1, default is 1.
32920
+ * The normalized end time of the clip, the range is 0 to 1, default is 1.
32643
32921
  */ function get() {
32644
32922
  return this._clipEndTime;
32645
32923
  },
@@ -32655,6 +32933,8 @@
32655
32933
  */ var AnimatorStateMachine = /*#__PURE__*/ function() {
32656
32934
  var AnimatorStateMachine = function AnimatorStateMachine() {
32657
32935
  /** The list of states. */ this.states = [];
32936
+ /** @internal */ this._entryTransitions = [];
32937
+ /** @internal */ this._anyStateTransitions = [];
32658
32938
  /** @internal */ this._statesMap = {};
32659
32939
  };
32660
32940
  var _proto = AnimatorStateMachine.prototype;
@@ -32703,17 +32983,62 @@
32703
32983
  }
32704
32984
  return name1;
32705
32985
  };
32986
+ _proto.addEntryStateTransition = function addEntryStateTransition(transitionOrAnimatorState) {
32987
+ var transition;
32988
+ if (_instanceof1$2(transitionOrAnimatorState, AnimatorState)) {
32989
+ transition = new AnimatorStateTransition();
32990
+ transition.destinationState = transitionOrAnimatorState;
32991
+ } else {
32992
+ transition = transitionOrAnimatorState;
32993
+ }
32994
+ this._entryTransitions.push(transition);
32995
+ return transition;
32996
+ };
32997
+ /**
32998
+ * Remove an entry transition.
32999
+ * @param transition - The transition
33000
+ */ _proto.removeEntryStateTransition = function removeEntryStateTransition(transition) {
33001
+ var index = this._entryTransitions.indexOf(transition);
33002
+ index !== -1 && this._entryTransitions.splice(index, 1);
33003
+ };
33004
+ _proto.addAnyStateTransition = function addAnyStateTransition(transitionOrAnimatorState) {
33005
+ var transition;
33006
+ if (_instanceof1$2(transitionOrAnimatorState, AnimatorState)) {
33007
+ transition = new AnimatorStateTransition();
33008
+ transition.destinationState = transitionOrAnimatorState;
33009
+ } else {
33010
+ transition = transitionOrAnimatorState;
33011
+ }
33012
+ this._anyStateTransitions.push(transition);
33013
+ return transition;
33014
+ };
33015
+ /**
33016
+ * Remove an any transition.
33017
+ * @param transition - The transition
33018
+ */ _proto.removeAnyStateTransition = function removeAnyStateTransition(transition) {
33019
+ var index = this._anyStateTransitions.indexOf(transition);
33020
+ index !== -1 && this._anyStateTransitions.splice(index, 1);
33021
+ };
33022
+ _create_class$2(AnimatorStateMachine, [
33023
+ {
33024
+ key: "entryTransitions",
33025
+ get: /**
33026
+ * The list of entry transitions in the state machine.
33027
+ */ function get() {
33028
+ return this._entryTransitions;
33029
+ }
33030
+ },
33031
+ {
33032
+ key: "anyStateTransitions",
33033
+ get: /**
33034
+ * The list of AnyState transitions.
33035
+ */ function get() {
33036
+ return this._anyStateTransitions;
33037
+ }
33038
+ }
33039
+ ]);
32706
33040
  return AnimatorStateMachine;
32707
33041
  }();
32708
- exports.AnimatorConditionMode = void 0;
32709
- (function(AnimatorConditionMode) {
32710
- AnimatorConditionMode[AnimatorConditionMode["If"] = 0] = "If";
32711
- AnimatorConditionMode[AnimatorConditionMode["IfNot"] = 1] = "IfNot";
32712
- AnimatorConditionMode[AnimatorConditionMode["Greater"] = 2] = "Greater";
32713
- AnimatorConditionMode[AnimatorConditionMode["Less"] = 3] = "Less";
32714
- AnimatorConditionMode[AnimatorConditionMode["Equals"] = 4] = "Equals";
32715
- AnimatorConditionMode[AnimatorConditionMode["NotEquals"] = 5] = "NotEquals";
32716
- })(exports.AnimatorConditionMode || (exports.AnimatorConditionMode = {}));
32717
33042
  /**
32718
33043
  * Keyframe.
32719
33044
  * @typeParam V - Type of Keyframe value
@@ -40214,6 +40539,7 @@
40214
40539
  this.resourceManager = resourceManager;
40215
40540
  this.params = params;
40216
40541
  this.accessorBufferCache = {};
40542
+ this.needAnimatorController = false;
40217
40543
  this._resourceCache = new Map();
40218
40544
  this._progress = {
40219
40545
  taskDetail: {},
@@ -40241,16 +40567,15 @@
40241
40567
  return Promise.resolve(null);
40242
40568
  }
40243
40569
  var cache = this._resourceCache;
40244
- var isOnlyOne = type === 0 || type === 1;
40245
- var cacheKey = isOnlyOne || index === undefined ? "" + type : type + ":" + index;
40570
+ var cacheKey = index === undefined ? "" + type : type + ":" + index;
40246
40571
  var resource = cache.get(cacheKey);
40247
40572
  if (resource) {
40248
40573
  return resource;
40249
40574
  }
40250
- if (isOnlyOne) {
40251
- resource = parser.parse(this);
40252
- } else {
40253
- var glTFItems = this.glTF[glTFSchemaMap[type]];
40575
+ var glTFSchemaKey = glTFSchemaMap[type];
40576
+ var isSubAsset = !!glTFResourceMap[type];
40577
+ if (glTFSchemaKey) {
40578
+ var glTFItems = this.glTF[glTFSchemaKey];
40254
40579
  if (glTFItems && (index === undefined || glTFItems[index])) {
40255
40580
  if (index === undefined) {
40256
40581
  resource = type === 8 ? glTFItems.map(function(_, index) {
@@ -40260,11 +40585,14 @@
40260
40585
  }));
40261
40586
  } else {
40262
40587
  resource = parser.parse(this, index);
40263
- this._handleSubAsset(resource, type, index);
40588
+ isSubAsset && this._handleSubAsset(resource, type, index);
40264
40589
  }
40265
40590
  } else {
40266
40591
  resource = Promise.resolve(null);
40267
40592
  }
40593
+ } else {
40594
+ resource = parser.parse(this, index);
40595
+ isSubAsset && this._handleSubAsset(resource, type, index);
40268
40596
  }
40269
40597
  cache.set(cacheKey, resource);
40270
40598
  return resource;
@@ -40273,6 +40601,7 @@
40273
40601
  var _this = this;
40274
40602
  var promise = this.get(0).then(function(json) {
40275
40603
  _this.glTF = json;
40604
+ _this.needAnimatorController = !!(json.skins || json.animations);
40276
40605
  return Promise.all([
40277
40606
  _this.get(1),
40278
40607
  _this.get(5),
@@ -40280,11 +40609,14 @@
40280
40609
  _this.get(7),
40281
40610
  _this.get(9),
40282
40611
  _this.get(10),
40612
+ _this.get(11),
40283
40613
  _this.get(2)
40284
40614
  ]).then(function() {
40285
40615
  var glTFResource = _this.glTFResource;
40286
- if (glTFResource.skins || glTFResource.animations) {
40287
- _this._createAnimator(_this, glTFResource.animations);
40616
+ var animatorController = glTFResource.animatorController;
40617
+ if (animatorController) {
40618
+ var animator = glTFResource._defaultSceneRoot.addComponent(Animator);
40619
+ animator.animatorController = animatorController;
40288
40620
  }
40289
40621
  _this.resourceManager.addContentRestorer(_this.contentRestorer);
40290
40622
  return glTFResource;
@@ -40303,40 +40635,21 @@
40303
40635
  _this._setTaskCompleteProgress(++task.loaded, task.total);
40304
40636
  });
40305
40637
  };
40306
- _proto._createAnimator = function _createAnimator(context, animations) {
40307
- var defaultSceneRoot = context.glTFResource.defaultSceneRoot;
40308
- var animator = defaultSceneRoot.addComponent(Animator);
40309
- var animatorController = new AnimatorController();
40310
- var layer = new AnimatorControllerLayer("layer");
40311
- var animatorStateMachine = new AnimatorStateMachine();
40312
- animatorController.addLayer(layer);
40313
- animator.animatorController = animatorController;
40314
- layer.stateMachine = animatorStateMachine;
40315
- if (animations) {
40316
- for(var i = 0; i < animations.length; i++){
40317
- var animationClip = animations[i];
40318
- var name = animationClip.name;
40319
- var uniqueName = animatorStateMachine.makeUniqueStateName(name);
40320
- if (uniqueName !== name) {
40321
- console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
40322
- }
40323
- var animatorState = animatorStateMachine.addState(uniqueName);
40324
- animatorState.clip = animationClip;
40325
- }
40326
- }
40327
- };
40328
40638
  _proto._handleSubAsset = function _handleSubAsset(resource, type, index) {
40329
40639
  var _this = this;
40330
40640
  var glTFResourceKey = glTFResourceMap[type];
40331
- if (!glTFResourceKey) return;
40332
40641
  if (type === 8) {
40333
40642
  var _this_glTFResource, _glTFResourceKey;
40334
40643
  ((_this_glTFResource = this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = resource;
40335
40644
  } else {
40336
40645
  var url = this.glTFResource.url;
40337
40646
  resource.then(function(item) {
40338
- var _this_glTFResource, _glTFResourceKey;
40339
- ((_this_glTFResource = _this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = item;
40647
+ if (index == undefined) {
40648
+ _this.glTFResource[glTFResourceKey] = item;
40649
+ } else {
40650
+ var _this_glTFResource, _glTFResourceKey;
40651
+ ((_this_glTFResource = _this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = item;
40652
+ }
40340
40653
  if (type === 7) {
40341
40654
  for(var i = 0, length = item.length; i < length; i++){
40342
40655
  var mesh = item[i];
@@ -40384,11 +40697,12 @@
40384
40697
  GLTFParserType[GLTFParserType["Entity"] = 8] = "Entity";
40385
40698
  GLTFParserType[GLTFParserType["Skin"] = 9] = "Skin";
40386
40699
  GLTFParserType[GLTFParserType["Animation"] = 10] = "Animation";
40700
+ GLTFParserType[GLTFParserType["AnimatorController"] = 11] = "AnimatorController";
40387
40701
  })(exports.GLTFParserType || (exports.GLTFParserType = {}));
40388
40702
  var _obj;
40389
40703
  var glTFSchemaMap = (_obj = {}, _obj[2] = "scenes", _obj[3] = "buffers", _obj[5] = "textures", _obj[6] = "materials", _obj[7] = "meshes", _obj[8] = "nodes", _obj[9] = "skins", _obj[10] = "animations", _obj[4] = "bufferViews", _obj);
40390
40704
  var _obj1;
40391
- var glTFResourceMap = (_obj1 = {}, _obj1[2] = "_sceneRoots", _obj1[5] = "textures", _obj1[6] = "materials", _obj1[7] = "meshes", _obj1[8] = "entities", _obj1[9] = "skins", _obj1[10] = "animations", _obj1);
40705
+ var glTFResourceMap = (_obj1 = {}, _obj1[2] = "_sceneRoots", _obj1[5] = "textures", _obj1[6] = "materials", _obj1[7] = "meshes", _obj1[8] = "entities", _obj1[9] = "skins", _obj1[10] = "animations", _obj1[11] = "animatorController", _obj1);
40392
40706
  function registerGLTFParser(pipeline) {
40393
40707
  return function(Parser) {
40394
40708
  var parser = new Parser();
@@ -43141,6 +43455,47 @@
43141
43455
  exports.GLTFBufferViewParser = __decorate([
43142
43456
  registerGLTFParser(exports.GLTFParserType.BufferView)
43143
43457
  ], exports.GLTFBufferViewParser);
43458
+ exports.GLTFAnimatorControllerParser = /*#__PURE__*/ function(GLTFParser1) {
43459
+ var GLTFAnimatorControllerParser = function GLTFAnimatorControllerParser() {
43460
+ return GLTFParser1.apply(this, arguments);
43461
+ };
43462
+ _inherits(GLTFAnimatorControllerParser, GLTFParser1);
43463
+ var _proto = GLTFAnimatorControllerParser.prototype;
43464
+ _proto.parse = function parse(context) {
43465
+ var _this = this;
43466
+ if (!context.needAnimatorController) {
43467
+ return Promise.resolve(null);
43468
+ }
43469
+ return context.get(exports.GLTFParserType.Animation).then(function(animations) {
43470
+ var animatorController = _this._createAnimatorController(animations);
43471
+ return Promise.resolve(animatorController);
43472
+ });
43473
+ };
43474
+ _proto._createAnimatorController = function _createAnimatorController(animations) {
43475
+ var animatorController = new AnimatorController();
43476
+ var layer = new AnimatorControllerLayer("layer");
43477
+ var animatorStateMachine = new AnimatorStateMachine();
43478
+ animatorController.addLayer(layer);
43479
+ layer.stateMachine = animatorStateMachine;
43480
+ if (animations) {
43481
+ for(var i = 0; i < animations.length; i++){
43482
+ var animationClip = animations[i];
43483
+ var name = animationClip.name;
43484
+ var uniqueName = animatorStateMachine.makeUniqueStateName(name);
43485
+ if (uniqueName !== name) {
43486
+ console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
43487
+ }
43488
+ var animatorState = animatorStateMachine.addState(uniqueName);
43489
+ animatorState.clip = animationClip;
43490
+ }
43491
+ }
43492
+ return animatorController;
43493
+ };
43494
+ return GLTFAnimatorControllerParser;
43495
+ }(GLTFParser);
43496
+ exports.GLTFAnimatorControllerParser = __decorate([
43497
+ registerGLTFParser(exports.GLTFParserType.AnimatorController)
43498
+ ], exports.GLTFAnimatorControllerParser);
43144
43499
  // Source: https://github.com/zeux/meshoptimizer/blob/master/js/meshopt_decoder.js
43145
43500
  var MeshoptDecoder = function() {
43146
43501
  var unpack = function unpack(data) {
@@ -43546,15 +43901,20 @@
43546
43901
  var dataRGBA = new Uint8Array(4 * width * height);
43547
43902
  var offset = 0, pos = 0;
43548
43903
  var ptrEnd = 4 * scanLineWidth;
43549
- var rgbeStart = new Uint8Array(4);
43550
43904
  var scanLineBuffer = new Uint8Array(ptrEnd);
43551
43905
  var numScanLines = height; // read in each successive scanLine
43552
43906
  while(numScanLines > 0 && pos < byteLength){
43553
- rgbeStart[0] = buffer[pos++];
43554
- rgbeStart[1] = buffer[pos++];
43555
- rgbeStart[2] = buffer[pos++];
43556
- rgbeStart[3] = buffer[pos++];
43557
- if (2 != rgbeStart[0] || 2 != rgbeStart[1] || (rgbeStart[2] << 8 | rgbeStart[3]) != scanLineWidth) {
43907
+ var a = buffer[pos++];
43908
+ var b = buffer[pos++];
43909
+ var c = buffer[pos++];
43910
+ var d = buffer[pos++];
43911
+ if (a != 2 || b != 2 || c & 0x80 || width < 8 || width > 32767) {
43912
+ // this file is not run length encoded
43913
+ // read values sequentially
43914
+ return buffer;
43915
+ }
43916
+ if ((c << 8 | d) != scanLineWidth) {
43917
+ // eslint-disable-next-line no-throw-literal
43558
43918
  throw "HDR Bad header format, wrong scan line width";
43559
43919
  }
43560
43920
  // read each of the four channels for the scanline into the buffer
@@ -43980,72 +44340,59 @@
43980
44340
  _this.request(item.url, _extends({}, item, {
43981
44341
  type: "json"
43982
44342
  })).then(function(materialSchema) {
44343
+ var _loop = function _loop(key) {
44344
+ var _shaderData_key = shaderData[key], type = _shaderData_key.type, value = _shaderData_key.value;
44345
+ switch(type){
44346
+ case "Vector2":
44347
+ materialShaderData.setVector2(key, new Vector2(value.x, value.y));
44348
+ break;
44349
+ case "Vector3":
44350
+ materialShaderData.setVector3(key, new Vector3(value.x, value.y, value.z));
44351
+ break;
44352
+ case "Vector4":
44353
+ materialShaderData.setVector4(key, new Vector4(value.x, value.y, value.z, value.w));
44354
+ break;
44355
+ case "Color":
44356
+ materialShaderData.setColor(key, new Color(value.r, value.g, value.b, value.a));
44357
+ break;
44358
+ case "Float":
44359
+ materialShaderData.setFloat(key, value);
44360
+ break;
44361
+ case "Texture":
44362
+ texturePromises.push(resourceManager.getResourceByRef(value).then(function(texture) {
44363
+ materialShaderData.setTexture(key, texture);
44364
+ }));
44365
+ break;
44366
+ case "Boolean":
44367
+ materialShaderData.setInt(key, value ? 1 : 0);
44368
+ break;
44369
+ case "Integer":
44370
+ materialShaderData.setInt(key, Number(value));
44371
+ break;
44372
+ }
44373
+ };
43983
44374
  var engine = resourceManager.engine;
43984
- var shaderRef = materialSchema.shaderRef, shader = materialSchema.shader;
43985
- if (shaderRef) {
43986
- resolve(resourceManager // @ts-ignore
43987
- .getResourceByRef(shaderRef).then(function(shaderObject) {
43988
- return _this.getMaterialByShader(materialSchema, shaderObject, engine);
43989
- }));
43990
- } else {
43991
- // compatible with 1.2-pre version material schema
43992
- var shaderObject = Shader.find(shader);
43993
- resolve(_this.getMaterialByShader(materialSchema, shaderObject, engine));
44375
+ var name = materialSchema.name, shader = materialSchema.shader, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
44376
+ var material = new Material(engine, Shader.find(shader));
44377
+ material.name = name;
44378
+ var texturePromises = new Array();
44379
+ var materialShaderData = material.shaderData;
44380
+ for(var key in shaderData)_loop(key);
44381
+ for(var i = 0, length = macros.length; i < length; i++){
44382
+ var _macros_i = macros[i], name1 = _macros_i.name, value = _macros_i.value;
44383
+ if (value == undefined) {
44384
+ materialShaderData.enableMacro(name1);
44385
+ } else {
44386
+ materialShaderData.enableMacro(name1, value);
44387
+ }
43994
44388
  }
44389
+ parseProperty(material, "renderState", renderState);
44390
+ return Promise.all(texturePromises).then(function() {
44391
+ resolve(material);
44392
+ });
43995
44393
  }).catch(reject);
43996
44394
  });
43997
44395
  };
43998
- _proto.getMaterialByShader = function getMaterialByShader(materialSchema, shader, engine) {
43999
- var _loop = function _loop(key) {
44000
- var _shaderData_key = shaderData[key], type = _shaderData_key.type, value = _shaderData_key.value;
44001
- switch(type){
44002
- case "Vector2":
44003
- materialShaderData.setVector2(key, new Vector2(value.x, value.y));
44004
- break;
44005
- case "Vector3":
44006
- materialShaderData.setVector3(key, new Vector3(value.x, value.y, value.z));
44007
- break;
44008
- case "Vector4":
44009
- materialShaderData.setVector4(key, new Vector4(value.x, value.y, value.z, value.w));
44010
- break;
44011
- case "Color":
44012
- materialShaderData.setColor(key, new Color(value.r, value.g, value.b, value.a));
44013
- break;
44014
- case "Float":
44015
- materialShaderData.setFloat(key, value);
44016
- break;
44017
- case "Texture":
44018
- texturePromises.push(engine.resourceManager.getResourceByRef(value).then(function(texture) {
44019
- materialShaderData.setTexture(key, texture);
44020
- }));
44021
- break;
44022
- case "Boolean":
44023
- materialShaderData.setInt(key, value ? 1 : 0);
44024
- break;
44025
- case "Integer":
44026
- materialShaderData.setInt(key, Number(value));
44027
- break;
44028
- }
44029
- };
44030
- var name = materialSchema.name, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
44031
- var material = new Material(engine, shader);
44032
- material.name = name;
44033
- var texturePromises = new Array();
44034
- var materialShaderData = material.shaderData;
44035
- for(var key in shaderData)_loop(key);
44036
- for(var i = 0, length = macros.length; i < length; i++){
44037
- var _macros_i = macros[i], name1 = _macros_i.name, value = _macros_i.value;
44038
- if (value == undefined) {
44039
- materialShaderData.enableMacro(name1);
44040
- } else {
44041
- materialShaderData.enableMacro(name1, value);
44042
- }
44043
- }
44044
- parseProperty(material, "renderState", renderState);
44045
- return Promise.all(texturePromises).then(function() {
44046
- return material;
44047
- });
44048
- };
44049
44396
  return MaterialLoader;
44050
44397
  }(Loader);
44051
44398
  MaterialLoader = __decorate([
@@ -44484,104 +44831,6 @@
44484
44831
  ""
44485
44832
  ])
44486
44833
  ], TextureCubeLoader);
44487
- var ShaderLoader = /*#__PURE__*/ function(Loader1) {
44488
- var ShaderLoader = function ShaderLoader() {
44489
- return Loader1.apply(this, arguments);
44490
- };
44491
- _inherits(ShaderLoader, Loader1);
44492
- var _proto = ShaderLoader.prototype;
44493
- _proto.load = function load(item, resourceManager) {
44494
- var _this = this;
44495
- return this.request(item.url, _extends({}, item, {
44496
- type: "text"
44497
- })).then(function(code) {
44498
- var builtinShader = _this.getBuiltinShader(code);
44499
- if (builtinShader) {
44500
- return Shader.find(builtinShader);
44501
- }
44502
- var matches = code.matchAll(/^[ \t]*#include +"([^$\\"]+)"/gm);
44503
- return Promise.all(Array.from(matches).map(function(m) {
44504
- var path = m[1];
44505
- if (path) {
44506
- // @ts-ignore
44507
- var resource = resourceManager._virtualPathMap[path];
44508
- if (!resource) return;
44509
- return resourceManager.load({
44510
- type: exports.AssetType.ShaderChunk,
44511
- url: resource,
44512
- params: {
44513
- includeKey: path
44514
- }
44515
- });
44516
- }
44517
- })).then(function() {
44518
- return Shader.create(code);
44519
- });
44520
- });
44521
- };
44522
- _proto.getBuiltinShader = function getBuiltinShader(code) {
44523
- var match = code.match(/^\s*\/\/\s*@builtin\s+(\w+)/);
44524
- if (match && match[1]) return match[1];
44525
- };
44526
- return ShaderLoader;
44527
- }(Loader);
44528
- ShaderLoader = __decorate([
44529
- resourceLoader(exports.AssetType.Shader, [
44530
- "gs",
44531
- "gsl"
44532
- ], false)
44533
- ], ShaderLoader);
44534
- var ShaderChunkLoader = /*#__PURE__*/ function(Loader1) {
44535
- var ShaderChunkLoader = function ShaderChunkLoader() {
44536
- return Loader1.apply(this, arguments);
44537
- };
44538
- _inherits(ShaderChunkLoader, Loader1);
44539
- var _proto = ShaderChunkLoader.prototype;
44540
- _proto.load = function load(item, resourceManager) {
44541
- return this.request(item.url, _extends({}, item, {
44542
- type: "text"
44543
- })).then(/*#__PURE__*/ _async_to_generator(function(code) {
44544
- var includeKey, matches;
44545
- return __generator(this, function(_state) {
44546
- switch(_state.label){
44547
- case 0:
44548
- includeKey = item.params.includeKey;
44549
- ShaderFactory.registerInclude(includeKey, code);
44550
- matches = code.matchAll(/^[ \t]*#include +"([^$\\"]+)"/gm);
44551
- return [
44552
- 4,
44553
- Promise.all(Array.from(matches).map(function(m) {
44554
- var path = m[1];
44555
- if (path) {
44556
- // @ts-ignore
44557
- var resource = resourceManager._virtualPathMap[path];
44558
- if (!resource) return;
44559
- return resourceManager.load({
44560
- type: exports.AssetType.ShaderChunk,
44561
- url: resource,
44562
- params: {
44563
- includeKey: path
44564
- }
44565
- });
44566
- }
44567
- }))
44568
- ];
44569
- case 1:
44570
- _state.sent();
44571
- return [
44572
- 2
44573
- ];
44574
- }
44575
- });
44576
- }));
44577
- };
44578
- return ShaderChunkLoader;
44579
- }(Loader);
44580
- ShaderChunkLoader = __decorate([
44581
- resourceLoader(exports.AssetType.ShaderChunk, [
44582
- "glsl"
44583
- ], false)
44584
- ], ShaderChunkLoader);
44585
44834
  var SceneLoader = /*#__PURE__*/ function(Loader1) {
44586
44835
  var SceneLoader = function SceneLoader() {
44587
44836
  return Loader1.apply(this, arguments);
@@ -45071,7 +45320,7 @@
45071
45320
  ], KHR_materials_anisotropy);
45072
45321
 
45073
45322
  //@ts-ignore
45074
- var version = "0.0.0-experimental-shaderlab.2";
45323
+ var version = "0.0.0-experimental-stateMachine.0";
45075
45324
  console.log("Galacean engine version: " + version);
45076
45325
  for(var key in CoreObjects){
45077
45326
  Loader.registerClass(key, CoreObjects[key]);