targetedAnimationPropertyGridComponent.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 "../../../../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<ITargetedAnimationGridComponentProps> {
  24. // private _isCurveEditorOpen: boolean;
  25. private _animationGroup: AnimationGroup | undefined;
  26. constructor(props: ITargetedAnimationGridComponentProps) {
  27. super(props);
  28. this._animationGroup = this.props.scene.animationGroups.find((ag) => {
  29. let ta = ag.targetedAnimations.find((ta) => ta === this.props.targetedAnimation);
  30. return ta !== undefined;
  31. });
  32. }
  33. // onOpenAnimationCurveEditor = () => {
  34. // this._isCurveEditorOpen = true;
  35. // };
  36. // onCloseAnimationCurveEditor = (window: Window | null) => {
  37. // this._isCurveEditorOpen = false;
  38. // if (window !== null) {
  39. // window.close();
  40. // }
  41. // };
  42. playOrPause = () => {
  43. if (this._animationGroup) {
  44. if (this._animationGroup.isPlaying) {
  45. this._animationGroup.stop();
  46. } else {
  47. this._animationGroup.start();
  48. }
  49. this.forceUpdate();
  50. }
  51. };
  52. deleteAnimation = () => {
  53. if (this._animationGroup) {
  54. let index = this._animationGroup.targetedAnimations.indexOf(this.props.targetedAnimation);
  55. if (index > -1) {
  56. this._animationGroup.targetedAnimations.splice(index, 1);
  57. this.props.onSelectionChangedObservable?.notifyObservers(null);
  58. if (this._animationGroup.isPlaying) {
  59. this._animationGroup.stop();
  60. this._animationGroup.start();
  61. }
  62. }
  63. }
  64. };
  65. render() {
  66. const targetedAnimation = this.props.targetedAnimation;
  67. return (
  68. <div className="pane">
  69. <LineContainerComponent globalState={this.props.globalState} title="GENERAL">
  70. <TextLineComponent label="Class" value={targetedAnimation.getClassName()} />
  71. <TextInputLineComponent lockObject={this.props.lockObject} label="Name" target={targetedAnimation.animation} propertyName="name" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  72. {targetedAnimation.target.name && <TextLineComponent label="Target" value={targetedAnimation.target.name} onLink={() => this.props.globalState.onSelectionChangedObservable.notifyObservers(targetedAnimation)} />}
  73. {/* <ButtonLineComponent label="Edit animation" onClick={this.onOpenAnimationCurveEditor} />
  74. {this._isCurveEditorOpen && (
  75. <PopupComponent
  76. id="curve-editor"
  77. title="Curve Animation Editor"
  78. size={{ width: 1024, height: 512 }}
  79. onOpen={(window: Window) => {}}
  80. onClose={this.onCloseAnimationCurveEditor}
  81. >
  82. <AnimationCurveEditorComponent
  83. scene={this.props.scene}
  84. entity={targetedAnimation as any}
  85. playOrPause={this.playOrPause}
  86. lockObject={this.props.lockObject}
  87. globalState={this.props.globalState}
  88. />
  89. </PopupComponent>
  90. )} */}
  91. <ButtonLineComponent label="Dispose" onClick={this.deleteAnimation} />
  92. </LineContainerComponent>
  93. </div>
  94. );
  95. }
  96. }