genericNodeModel.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import * as React from "react";
  2. import { Nullable } from 'babylonjs/types';
  3. import { Vector2, Vector3, Vector4, Matrix } from 'babylonjs/Maths/math';
  4. import { DefaultNodeModel } from '../defaultNodeModel';
  5. import { DiagramModel } from 'storm-react-diagrams/dist/@types/src/models/DiagramModel';
  6. import { GraphEditor, NodeCreationOptions } from '../../../graphEditor';
  7. import { GlobalState } from '../../../globalState';
  8. import { TextLineComponent } from '../../../sharedComponents/textLineComponent';
  9. import { LineContainerComponent } from '../../../sharedComponents/lineContainerComponent';
  10. import { TextInputLineComponent } from '../../../sharedComponents/textInputLineComponent';
  11. import { CheckBoxLineComponent } from '../../../sharedComponents/checkBoxLineComponent';
  12. import { TransformBlock } from 'babylonjs/Materials/Node/Blocks/transformBlock';
  13. /**
  14. * Generic node model which stores information about a node editor block
  15. */
  16. export class GenericNodeModel extends DefaultNodeModel {
  17. /**
  18. * Vector2 for the node if it exists
  19. */
  20. public vector2: Nullable<Vector2> = null;
  21. /**
  22. * Vector3 for the node if it exists
  23. */
  24. public vector3: Nullable<Vector3> = null;
  25. /**
  26. * Vector4 for the node if it exists
  27. */
  28. public vector4: Nullable<Vector4> = null;
  29. /**
  30. * Matrix for the node if it exists
  31. */
  32. public matrix: Nullable<Matrix> = null;
  33. /**
  34. * Constructs the node model
  35. */
  36. constructor() {
  37. super("generic");
  38. }
  39. prepare(options: NodeCreationOptions, nodes: Array<DefaultNodeModel>, model: DiagramModel, graphEditor: GraphEditor) {
  40. super.prepare(options, nodes, model, graphEditor);
  41. }
  42. renderProperties(globalState: GlobalState) {
  43. return (
  44. <div>
  45. <LineContainerComponent title="GENERAL">
  46. <TextInputLineComponent globalState={globalState} label="Name" propertyName="name" target={this.block!} onChange={() => globalState.onUpdateRequiredObservable.notifyObservers()} />
  47. <TextLineComponent label="Type" value={this.block!.getClassName()} />
  48. </LineContainerComponent>
  49. {
  50. this.block!.getClassName() === "TransformBlock" &&
  51. <LineContainerComponent title="PROPERTIES">
  52. <CheckBoxLineComponent label="Transform as direction" onSelect={value => {
  53. let transformBlock = this.block as TransformBlock;
  54. if (value) {
  55. transformBlock.complementW = 0;
  56. } else {
  57. transformBlock.complementW = 1;
  58. }
  59. globalState.onRebuildRequiredObservable.notifyObservers();
  60. }} isSelected={() => (this.block as TransformBlock).complementW === 0} />
  61. </LineContainerComponent>
  62. }
  63. {
  64. this.block!.getClassName() === "PerturbNormalBlock" &&
  65. <LineContainerComponent title="PROPERTIES">
  66. <CheckBoxLineComponent label="Invert X axis" target={this.block} propertyName="invertX" onValueChanged={() => globalState.onRebuildRequiredObservable.notifyObservers()} />
  67. <CheckBoxLineComponent label="Invert Y axis" target={this.block} propertyName="invertY" onValueChanged={() => globalState.onRebuildRequiredObservable.notifyObservers()}/>
  68. </LineContainerComponent>
  69. }
  70. </div>
  71. );
  72. }
  73. }