babylon.directActions.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. module BABYLON {
  2. export class SwitchBooleanAction extends Action {
  3. private _target: any;
  4. private _property: string;
  5. constructor(trigger: number, public targetType: number, public targetName: string, public propertyPath: string, condition?: Condition) {
  6. super(trigger, condition);
  7. }
  8. public _prepare(): void {
  9. this._target = this._getTarget(this.targetType, this.targetName);
  10. this._target = this._getEffectiveTarget(this._target, this.propertyPath);
  11. this._property = this._getProperty(this.propertyPath);
  12. }
  13. public execute(): void {
  14. this._target[this._property] = !this._target[this._property];
  15. }
  16. }
  17. export class SetValueAction extends Action {
  18. private _target: any;
  19. private _property: string;
  20. constructor(trigger: number, public targetType: number, public targetName: string, public propertyPath: string, public value: any, condition?: Condition) {
  21. super(trigger, condition);
  22. }
  23. public _prepare(): void {
  24. this._target = this._getTarget(this.targetType, this.targetName);
  25. this._target = this._getEffectiveTarget(this._target, this.propertyPath);
  26. this._property = this._getProperty(this.propertyPath);
  27. }
  28. public execute(): void {
  29. this._target[this._property] = this.value;
  30. }
  31. }
  32. export class PlayAnimationAction extends Action {
  33. private _target: any;
  34. constructor(trigger: number, public targetType: number, public targetName: string, public from: number, public to: number, public loop?: boolean, condition?: Condition) {
  35. super(trigger, condition);
  36. }
  37. public _prepare(): void {
  38. this._target = this._getTarget(this.targetType, this.targetName);
  39. }
  40. public execute(): void {
  41. var scene = this._actionManager.getScene();
  42. scene.beginAnimation(this._target, this.from, this.to, this.loop);
  43. }
  44. }
  45. export class StopAnimationAction extends Action {
  46. private _target: any;
  47. constructor(trigger: number, public targetType: number, public targetName: string, condition?: Condition) {
  48. super(trigger, condition);
  49. }
  50. public _prepare(): void {
  51. this._target = this._getTarget(this.targetType, this.targetName);
  52. }
  53. public execute(): void {
  54. var scene = this._actionManager.getScene();
  55. scene.stopAnimation(this._target);
  56. }
  57. }
  58. export class ExecuteCodeAction extends Action {
  59. constructor(trigger: number, public func: () => void, condition?: Condition) {
  60. super(trigger, condition);
  61. }
  62. public execute(): void {
  63. this.func();
  64. }
  65. }
  66. export class SetParentAction extends Action {
  67. private _parent: any;
  68. private _target: any;
  69. constructor(trigger: number, public targetType: number, public targetName: string, public parentType: number, public parentName: string, condition?: Condition) {
  70. super(trigger, condition);
  71. }
  72. public _prepare(): void {
  73. this._target = this._getTarget(this.targetType, this.targetName);
  74. this._parent = this._getTarget(this.parentType, this.parentName);
  75. }
  76. public execute(): void {
  77. if (this._target.parent === this._parent) {
  78. return;
  79. }
  80. var invertParentWorldMatrix = this._parent.getWorldMatrix().clone();
  81. invertParentWorldMatrix.invert();
  82. this._target.position = BABYLON.Vector3.TransformCoordinates(this._target.position, invertParentWorldMatrix);
  83. this._target.parent = this._parent;
  84. }
  85. }
  86. }