targetedAnimationPropertyGridComponent.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import * as React from "react";
  2. import { Observable } from "babylonjs/Misc/observable";
  3. import { TargetedAnimation } from "babylonjs/Animations/animationGroup";
  4. import { Scene } from "babylonjs/scene";
  5. import { PropertyChangedEvent } from "../../../../propertyChangedEvent";
  6. import { ButtonLineComponent } from "../../../lines/buttonLineComponent";
  7. import { LineContainerComponent } from "../../../lineContainerComponent";
  8. import { TextLineComponent } from "../../../lines/textLineComponent";
  9. import { LockObject } from "../lockObject";
  10. import { GlobalState } from "../../../../globalState";
  11. import { TextInputLineComponent } from "../../../lines/textInputLineComponent";
  12. import { PopupComponent } from "../animations/popupComponent";
  13. import { AnimationCurveEditorComponent } from "../animations/animationCurveEditorComponent";
  14. import { AnimationGroup } from "babylonjs/Animations/animationGroup";
  15. interface ITargetedAnimationGridComponentProps {
  16. globalState: GlobalState;
  17. targetedAnimation: TargetedAnimation;
  18. scene: Scene;
  19. lockObject: LockObject;
  20. onSelectionChangedObservable?: Observable<any>;
  21. onPropertyChangedObservable?: Observable<PropertyChangedEvent>;
  22. }
  23. export class TargetedAnimationGridComponent extends React.Component<
  24. ITargetedAnimationGridComponentProps
  25. > {
  26. private _isCurveEditorOpen: boolean;
  27. private _animationGroup: AnimationGroup | undefined;
  28. constructor(props: ITargetedAnimationGridComponentProps) {
  29. super(props);
  30. this._animationGroup = this.props.scene.animationGroups.find((ag) => {
  31. let ta = ag.targetedAnimations.find(
  32. (ta) => ta === this.props.targetedAnimation
  33. );
  34. return ta !== undefined;
  35. });
  36. }
  37. onOpenAnimationCurveEditor() {
  38. this._isCurveEditorOpen = true;
  39. }
  40. onCloseAnimationCurveEditor(window: Window | null) {
  41. this._isCurveEditorOpen = false;
  42. if (window !== null) {
  43. window.close();
  44. }
  45. }
  46. playOrPause() {
  47. if (this._animationGroup) {
  48. if (this._animationGroup.isPlaying) {
  49. this._animationGroup.stop();
  50. } else {
  51. this._animationGroup.start();
  52. }
  53. this.forceUpdate();
  54. }
  55. }
  56. deleteAnimation() {
  57. if (this._animationGroup) {
  58. let index = this._animationGroup.targetedAnimations.indexOf(
  59. this.props.targetedAnimation
  60. );
  61. if (index > -1) {
  62. this._animationGroup.targetedAnimations.splice(index, 1);
  63. this.props.onSelectionChangedObservable?.notifyObservers(null);
  64. if (this._animationGroup.isPlaying) {
  65. this._animationGroup.stop();
  66. this._animationGroup.start();
  67. }
  68. }
  69. }
  70. }
  71. render() {
  72. const targetedAnimation = this.props.targetedAnimation;
  73. return (
  74. <div className="pane">
  75. <LineContainerComponent
  76. globalState={this.props.globalState}
  77. title="GENERAL"
  78. >
  79. <TextLineComponent
  80. label="Class"
  81. value={targetedAnimation.getClassName()}
  82. />
  83. <TextInputLineComponent
  84. lockObject={this.props.lockObject}
  85. label="Name"
  86. target={targetedAnimation.animation}
  87. propertyName="name"
  88. onPropertyChangedObservable={this.props.onPropertyChangedObservable}
  89. />
  90. {targetedAnimation.target.name && (
  91. <TextLineComponent
  92. label="Target"
  93. value={targetedAnimation.target.name}
  94. onLink={() =>
  95. this.props.globalState.onSelectionChangedObservable.notifyObservers(
  96. targetedAnimation
  97. )
  98. }
  99. />
  100. )}
  101. <ButtonLineComponent
  102. label="Edit animation"
  103. onClick={() => this.onOpenAnimationCurveEditor()}
  104. />
  105. {this._isCurveEditorOpen && (
  106. <PopupComponent
  107. id="curve-editor"
  108. title="Curve Animation Editor"
  109. size={{ width: 1024, height: 512 }}
  110. onOpen={(window: Window) => {}}
  111. onClose={(window: Window) =>
  112. this.onCloseAnimationCurveEditor(window)
  113. }
  114. >
  115. <AnimationCurveEditorComponent
  116. scene={this.props.scene}
  117. entity={targetedAnimation as any}
  118. playOrPause={() => this.playOrPause()}
  119. lockObject={this.props.lockObject}
  120. close={(event) => this.onCloseAnimationCurveEditor(event.view)}
  121. />
  122. </PopupComponent>
  123. )}
  124. <ButtonLineComponent
  125. label="Dispose"
  126. onClick={() => this.deleteAnimation()}
  127. />
  128. </LineContainerComponent>
  129. </div>
  130. );
  131. }
  132. }