gradientNodePropertyComponent.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import * as React from "react";
  2. import { GradientBlockColorStep, GradientBlock } from 'babylonjs/Materials/Node/Blocks/gradientBlock';
  3. import { GradientStepComponent } from './gradientStepComponent';
  4. import { Color3 } from 'babylonjs/Maths/math.color';
  5. import { ButtonLineComponent } from '../lines/buttonLineComponent';
  6. import { IPropertyComponentProps } from './propertyComponentProps';
  7. export class GradientPropertyTabComponent extends React.Component<IPropertyComponentProps> {
  8. private _gradientBlock: GradientBlock;
  9. constructor(props: IPropertyComponentProps) {
  10. super(props)
  11. this._gradientBlock = this.props.block as GradientBlock;
  12. }
  13. forceRebuild() {
  14. this._gradientBlock.colorStepsUpdated();
  15. this.forceUpdate();
  16. }
  17. deleteStep(step: GradientBlockColorStep) {
  18. let index = this._gradientBlock.colorSteps.indexOf(step);
  19. if (index > -1) {
  20. this._gradientBlock.colorSteps.splice(index, 1);
  21. this.forceRebuild();
  22. }
  23. }
  24. addNewStep() {
  25. let newStep = new GradientBlockColorStep(1.0, Color3.White());
  26. this._gradientBlock.colorSteps.push(newStep);
  27. this.forceRebuild();
  28. }
  29. checkForReOrder() {
  30. this._gradientBlock.colorSteps.sort((a, b) => {
  31. return a.step - b.step;
  32. });
  33. this.forceRebuild();
  34. }
  35. render() {
  36. return (
  37. <div>
  38. <ButtonLineComponent label="Add new step" onClick={() => this.addNewStep()} />
  39. {
  40. this._gradientBlock.colorSteps.map((c, i) => {
  41. return (
  42. <GradientStepComponent globalState={this.props.globalState}
  43. onCheckForReOrder={() => this.checkForReOrder()}
  44. onUpdateStep={() => this.forceRebuild()}
  45. key={"step-" + i} lineIndex={i} step={c} onDelete={() => this.deleteStep(c)}/>
  46. )
  47. })
  48. }
  49. </div>
  50. );
  51. }
  52. }