genericNodePropertyComponent.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import * as React from "react";
  2. import { LineContainerComponent } from '../../sharedComponents/lineContainerComponent';
  3. import { IPropertyComponentProps } from './propertyComponentProps';
  4. import { CheckBoxLineComponent } from '../../sharedComponents/checkBoxLineComponent';
  5. import { FloatLineComponent } from '../../sharedComponents/floatLineComponent';
  6. import { SliderLineComponent } from '../../sharedComponents/sliderLineComponent';
  7. import { PropertyTypeForEdition, IPropertyDescriptionForEdition } from 'babylonjs/Materials/Node/nodeMaterialDecorator';
  8. export class GenericPropertyComponent extends React.Component<IPropertyComponentProps> {
  9. constructor(props: IPropertyComponentProps) {
  10. super(props);
  11. }
  12. render() {
  13. return (
  14. <>
  15. <GeneralPropertyTabComponent globalState={this.props.globalState} guiBlock={this.props.guiBlock}/>
  16. <GenericPropertyTabComponent globalState={this.props.globalState} guiBlock={this.props.guiBlock}/>
  17. </>
  18. );
  19. }
  20. }
  21. export class GeneralPropertyTabComponent extends React.Component<IPropertyComponentProps> {
  22. constructor(props: IPropertyComponentProps) {
  23. super(props);
  24. }
  25. render() {
  26. return (
  27. <>
  28. <LineContainerComponent title="GENERAL">
  29. </LineContainerComponent>
  30. </>
  31. );
  32. }
  33. }
  34. export class GenericPropertyTabComponent extends React.Component<IPropertyComponentProps> {
  35. constructor(props: IPropertyComponentProps) {
  36. super(props);
  37. }
  38. forceRebuild(notifiers?: { "rebuild"?: boolean; "update"?: boolean; }) {
  39. if (!notifiers || notifiers.update) {
  40. this.props.globalState.onUpdateRequiredObservable.notifyObservers();
  41. }
  42. if (!notifiers || notifiers.rebuild) {
  43. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  44. }
  45. }
  46. render() {
  47. const block = this.props.guiBlock,
  48. propStore: IPropertyDescriptionForEdition[] = (block as any)._propStore;
  49. if (!propStore) {
  50. return (
  51. <>
  52. </>
  53. );
  54. }
  55. const componentList: { [groupName: string]: JSX.Element[]} = {},
  56. groups: string[] = [];
  57. for (const { propertyName, displayName, type, groupName, options } of propStore) {
  58. let components = componentList[groupName];
  59. if (!components) {
  60. components = [];
  61. componentList[groupName] = components;
  62. groups.push(groupName);
  63. }
  64. switch (type) {
  65. case PropertyTypeForEdition.Boolean: {
  66. components.push(
  67. <CheckBoxLineComponent label={displayName} target={this.props.guiBlock} propertyName={propertyName} onValueChanged={() => this.forceRebuild(options.notifiers)} />
  68. );
  69. break;
  70. }
  71. case PropertyTypeForEdition.Float: {
  72. let cantDisplaySlider = (isNaN(options.min as number) || isNaN(options.max as number) || options.min === options.max);
  73. if (cantDisplaySlider) {
  74. components.push(
  75. <FloatLineComponent globalState={this.props.globalState} label={displayName} propertyName={propertyName} target={this.props.guiBlock} onChange={() => this.forceRebuild(options.notifiers)} />
  76. );
  77. } else {
  78. components.push(
  79. <SliderLineComponent label={displayName} target={this.props.guiBlock} globalState={this.props.globalState} propertyName={propertyName} step={Math.abs((options.max as number) - (options.min as number)) / 100.0} minimum={Math.min(options.min as number, options.max as number)} maximum={options.max as number} onChange={() => this.forceRebuild(options.notifiers)}/>
  80. );
  81. }
  82. break;
  83. }
  84. }
  85. }
  86. return (
  87. <>
  88. {
  89. groups.map((group) =>
  90. <LineContainerComponent title={group}>
  91. {componentList[group]}
  92. </LineContainerComponent>
  93. )
  94. }
  95. </>
  96. );
  97. }
  98. }