animationGroupMask.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * Enum used to define the mode for an animation group mask
  3. */
  4. export var AnimationGroupMaskMode;
  5. (function (AnimationGroupMaskMode) {
  6. /**
  7. * The mask defines the animatable target names that should be included
  8. */
  9. AnimationGroupMaskMode[AnimationGroupMaskMode["Include"] = 0] = "Include";
  10. /**
  11. * The mask defines the animatable target names in a "exclude" mode: all animatable targets will be animated except the ones defined in the mask
  12. */
  13. AnimationGroupMaskMode[AnimationGroupMaskMode["Exclude"] = 1] = "Exclude";
  14. })(AnimationGroupMaskMode || (AnimationGroupMaskMode = {}));
  15. /**
  16. * Defines a mask used to filter animation targets.
  17. * If you apply a mask to an animation group (see the AnimationGroup.mask property), only the animations whose target names match the mask will play.
  18. * Note that a target is defined by its name (string). This means that the same mask can be used for several animation groups, provided that their targets are named in the same way.
  19. */
  20. export class AnimationGroupMask {
  21. /**
  22. * Creates a new mask
  23. * @param names The list of target names to add to the mask (optional)
  24. * @param mode Defines the mode for the mask (default: AnimationGroupMaskMode.Include)
  25. */
  26. constructor(names,
  27. /**
  28. * Defines the mode for the mask
  29. */
  30. mode = AnimationGroupMaskMode.Include) {
  31. this.mode = mode;
  32. /**
  33. * Gets or sets a boolean indicating if the mask is disabled (default is false)
  34. */
  35. this.disabled = false;
  36. this._targetNames = new Set();
  37. if (names) {
  38. this.addTargetName(names);
  39. }
  40. }
  41. /**
  42. * Adds one or several target names to the mask
  43. * @param name The name(s) to add to the mask
  44. */
  45. addTargetName(name) {
  46. if (Array.isArray(name)) {
  47. for (const n of name) {
  48. this._targetNames.add(n);
  49. }
  50. return;
  51. }
  52. this._targetNames.add(name);
  53. }
  54. /**
  55. * Removes one or several target names from the mask
  56. * @param name The name(s) to remove from the mask
  57. */
  58. removeTargetName(name) {
  59. if (Array.isArray(name)) {
  60. for (const n of name) {
  61. this._targetNames.delete(n);
  62. }
  63. return;
  64. }
  65. this._targetNames.delete(name);
  66. }
  67. /**
  68. * Checks if the mask includes a target name.
  69. * This method is intended to know if a given target name is included in the mask, not if the name is actually retained by the mask (see retainsTarget() instead).
  70. * @param name The name to check with the mask
  71. * @returns True if the mask includes the name, false otherwise
  72. */
  73. hasTarget(name) {
  74. return this._targetNames.has(name);
  75. }
  76. /**
  77. * Checks if the mask retains a target name.
  78. * Note that in the "Exclude" mode, this will return false if the mask includes the name, and true otherwise!
  79. * This method is intended to know if a given target name is retained by the mask, not if the name is in the list of target names.
  80. * @param name The name to check with the mask
  81. * @returns True if the mask retains the name, false otherwise
  82. */
  83. retainsTarget(name) {
  84. return this._targetNames.has(name) === (this.mode === AnimationGroupMaskMode.Include);
  85. }
  86. }
  87. //# sourceMappingURL=animationGroupMask.js.map