babylon.action.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var Action = (function () {
  4. function Action(triggerOptions, condition) {
  5. this.triggerOptions = triggerOptions;
  6. if (triggerOptions.parameter) {
  7. this.trigger = triggerOptions.trigger;
  8. this._triggerParameter = triggerOptions.parameter;
  9. }
  10. else {
  11. this.trigger = triggerOptions;
  12. }
  13. this._nextActiveAction = this;
  14. this._condition = condition;
  15. }
  16. // Methods
  17. Action.prototype._prepare = function () {
  18. };
  19. Action.prototype.getTriggerParameter = function () {
  20. return this._triggerParameter;
  21. };
  22. Action.prototype._executeCurrent = function (evt) {
  23. if (this._nextActiveAction._condition) {
  24. var condition = this._nextActiveAction._condition;
  25. var currentRenderId = this._actionManager.getScene().getRenderId();
  26. // We cache the current evaluation for the current frame
  27. if (condition._evaluationId === currentRenderId) {
  28. if (!condition._currentResult) {
  29. return;
  30. }
  31. }
  32. else {
  33. condition._evaluationId = currentRenderId;
  34. if (!condition.isValid()) {
  35. condition._currentResult = false;
  36. return;
  37. }
  38. condition._currentResult = true;
  39. }
  40. }
  41. this._nextActiveAction.execute(evt);
  42. this.skipToNextActiveAction();
  43. };
  44. Action.prototype.execute = function (evt) {
  45. };
  46. Action.prototype.skipToNextActiveAction = function () {
  47. if (this._nextActiveAction._child) {
  48. if (!this._nextActiveAction._child._actionManager) {
  49. this._nextActiveAction._child._actionManager = this._actionManager;
  50. }
  51. this._nextActiveAction = this._nextActiveAction._child;
  52. }
  53. else {
  54. this._nextActiveAction = this;
  55. }
  56. };
  57. Action.prototype.then = function (action) {
  58. this._child = action;
  59. action._actionManager = this._actionManager;
  60. action._prepare();
  61. return action;
  62. };
  63. Action.prototype._getProperty = function (propertyPath) {
  64. return this._actionManager._getProperty(propertyPath);
  65. };
  66. Action.prototype._getEffectiveTarget = function (target, propertyPath) {
  67. return this._actionManager._getEffectiveTarget(target, propertyPath);
  68. };
  69. Action.prototype.serialize = function (parent) {
  70. };
  71. // Called by BABYLON.Action objects in serialize(...). Internal use
  72. Action.prototype._serialize = function (serializedAction, parent) {
  73. var serializationObject = {
  74. type: 1,
  75. children: [],
  76. name: serializedAction.name,
  77. properties: serializedAction.properties || []
  78. };
  79. // Serialize child
  80. if (this._child) {
  81. this._child.serialize(serializationObject);
  82. }
  83. // Check if "this" has a condition
  84. if (this._condition) {
  85. var serializedCondition = this._condition.serialize();
  86. serializedCondition.children.push(serializationObject);
  87. if (parent) {
  88. parent.children.push(serializedCondition);
  89. }
  90. return serializedCondition;
  91. }
  92. if (parent) {
  93. parent.children.push(serializationObject);
  94. }
  95. return serializationObject;
  96. };
  97. Action._SerializeValueAsString = function (value) {
  98. if (typeof value === "number") {
  99. return value.toString();
  100. }
  101. if (typeof value === "boolean") {
  102. return value ? "true" : "false";
  103. }
  104. if (value instanceof BABYLON.Vector2) {
  105. return value.x + ", " + value.y;
  106. }
  107. if (value instanceof BABYLON.Vector3) {
  108. return value.x + ", " + value.y + ", " + value.z;
  109. }
  110. if (value instanceof BABYLON.Color3) {
  111. return value.r + ", " + value.g + ", " + value.b;
  112. }
  113. if (value instanceof BABYLON.Color4) {
  114. return value.r + ", " + value.g + ", " + value.b + ", " + value.a;
  115. }
  116. return value; // string
  117. };
  118. Action._GetTargetProperty = function (target) {
  119. return {
  120. name: "target",
  121. targetType: target instanceof BABYLON.Mesh ? "MeshProperties"
  122. : target instanceof BABYLON.Light ? "LightProperties"
  123. : target instanceof BABYLON.Camera ? "CameraProperties"
  124. : "SceneProperties",
  125. value: target instanceof BABYLON.Scene ? "Scene" : target.name
  126. };
  127. };
  128. return Action;
  129. })();
  130. BABYLON.Action = Action;
  131. })(BABYLON || (BABYLON = {}));