nodeListComponent.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import * as React from "react";
  2. import { GlobalState } from '../../globalState';
  3. import { LineContainerComponent } from '../../sharedComponents/lineContainerComponent';
  4. import { DraggableLineComponent } from '../../sharedComponents/draggableLineComponent';
  5. require("./nodeList.scss");
  6. interface INodeListComponentProps {
  7. globalState: GlobalState;
  8. }
  9. export class NodeListComponent extends React.Component<INodeListComponentProps, {filter: string}> {
  10. constructor(props: INodeListComponentProps) {
  11. super(props);
  12. this.state = { filter: "" };
  13. }
  14. filterContent(filter: string) {
  15. this.setState({ filter: filter });
  16. }
  17. render() {
  18. // Block types used to create the menu from
  19. const allBlocks = {
  20. Animation: ["BonesBlock", "MorphTargetsBlock"],
  21. Output_Blocks: ["VertexOutputBlock", "FragmentOutputBlock", "AlphaTestBlock"],
  22. Interpolation: ["LerpBlock"],
  23. Range: ["ClampBlock", "RemapBlock", "NormalizeBlock"],
  24. Round: ["StepBlock"],
  25. Vector_Math: ["CrossBlock", "DotBlock", "TransformBlock", "FresnelBlock"],
  26. Basic_Math: ["AddBlock", "DivideBlock", "MultiplyBlock", "ScaleBlock", "SubtractBlock"],
  27. Trigonometry: [],
  28. Conversion_Blocks: ["ColorMergerBlock", "ColorSplitterBlock", "VectorMergerBlock", "VectorSplitterBlock"],
  29. Mesh_Attributes: ["InstancesBlock"],
  30. Matrices: ["Matrix"],
  31. Scene_Attributes: ["FogBlock","ImageProcessingBlock", "LightBlock", "ReflectionTextureBlock"],
  32. Inputs: ["Float", "Vector2", "Vector3", "Vector4", "Color3", "Color4", "TextureBlock"],
  33. }
  34. // Create node menu
  35. var blockMenu = []
  36. for (var key in allBlocks) {
  37. var blockList = (allBlocks as any)[key].filter((b: string) => !this.state.filter || b.toLowerCase().indexOf(this.state.filter.toLowerCase()) !== -1)
  38. .sort((a: string, b: string) => a.localeCompare(b))
  39. .map((block: any, i: number) => {
  40. return <DraggableLineComponent key={block} data={block} />
  41. });
  42. if (blockList.length) {
  43. blockMenu.push(
  44. <LineContainerComponent key={key + " blocks"} title={key.replace("_", " ")} closed={false}>
  45. {blockList}
  46. </LineContainerComponent>
  47. );
  48. }
  49. }
  50. return (
  51. <div id="nodeList" style={{ borderRightStyle: "solid", borderColor: "grey", borderWidth: "1px" }} >
  52. <div className="panes">
  53. <div className="pane">
  54. <div className="filter">
  55. <input type="text" placeholder="Filter" onChange={(evt) => this.filterContent(evt.target.value)} />
  56. </div>
  57. {blockMenu}
  58. </div>
  59. </div>
  60. </div>
  61. );
  62. }
  63. }