nodeListComponent.tsx 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import * as React from "react";
  2. import { GlobalState } from '../../globalState';
  3. import { LineContainerComponent } from '../../sharedComponents/lineContainerComponent';
  4. import { DraggableLineComponent } from '../../sharedComponents/draggableLineComponent';
  5. import { NodeMaterialModes } from 'babylonjs/Materials/Node/Enums/nodeMaterialModes';
  6. import { Observer } from 'babylonjs/Misc/observable';
  7. import { Nullable } from 'babylonjs/types';
  8. require("./nodeList.scss");
  9. interface INodeListComponentProps {
  10. globalState: GlobalState;
  11. }
  12. export class NodeListComponent extends React.Component<INodeListComponentProps, {filter: string}> {
  13. private _onResetRequiredObserver: Nullable<Observer<void>>;
  14. private static _Tooltips: {[key: string]: string} = {
  15. "BonesBlock": "Provides a world matrix for each vertex, based on skeletal (bone/joint) animation",
  16. "MorphTargetsBlock": "Provides the final positions, normals, tangents, and uvs based on morph targets in a mesh",
  17. "AddBlock": "Adds the left and right inputs of the same type together",
  18. "DistanceBlock": "Provides a distance vector based on the left and right input vectors",
  19. "DivideBlock": "Divides the left input by the right input of the same type",
  20. "LengthBlock": "Outputs the length of an input vector",
  21. "MaxBlock": "Outputs the largest value between the left and right inputs of the same type",
  22. "MinBlock": "Outputs the smallest value between the left and right inputs of the same type",
  23. "MultiplyBlock": "Multiplies the left and right inputs of the same type together",
  24. "NegateBlock": "Multiplies the input by -1",
  25. "OneMinusBlock": "Subtracts each channel of the input value from 1 (1 - input)",
  26. "RandomNumberBlock": "Provides a random number based on an input seed",
  27. "ReciprocalBlock": "Quotient of 1 divided by the input",
  28. "ScaleBlock": "Multiplies the input channels by a float factor",
  29. "SubtractBlock": "Subtracts the right input from the left input of the same type",
  30. "GradientBlock": "Returns the color in the gradient represented by the target value of the input",
  31. "PosterizeBlock": "Reduces the number of values in each channel to the number in the corresponding channel of steps",
  32. "ReplaceColorBlock": "Replaces a reference color in value with the color in replacement blended by distance",
  33. "ColorMergerBlock": "Combines float input channels into a color",
  34. "ColorSplitterBlock": "Separates color input channels into individual floats",
  35. "VectorMergerBlock": "Combines up to four input floats into a vector",
  36. "VectorSplitterBlock": "Separates vectors input channels into individual floats",
  37. "Color3": "A color made up of red, green, and blue channel values",
  38. "Color4": "A color made up of red, green, blue, and alpha channel values",
  39. "DeltaTimeBlock": "A float representing the time that has passed since the last frame was rendered",
  40. "Float": "A floating point number representing a value with a fractional component",
  41. "TextureBlock": "A node for reading a linked or embedded texture file",
  42. "TimeBlock": "A float value that represents the time that has passed since the scene was loaded",
  43. "Vector2": "a vector composed of X and Y channels",
  44. "Vector3": "a vector composed of X, Y, and Z channels",
  45. "Vector4": "a vector composed of X, Y, Z, and W channels",
  46. "LerpBlock": "Outputs a value that is a mix of the left and right inputs based on the target value",
  47. "NLerpBlock": "Outputs a value that is a mix of the left and right inputs based on the target's normalized value",
  48. "SmoothStepBlock": "Outputs a value based on a the input value's position on a curve between the two edge values",
  49. "StepBlock": "Outputs 1 for any input value above the edge input, outputs 0 for any input value below the edge input",
  50. "Matrix": "A 4x4 table of related values",
  51. "ProjectionMatrixBlock": "A matrix to remap points in 3D space to 2D plane relative to the screen",
  52. "ViewMatrixBlock": "A matrix to remap points in 3D space to 2D plane relative to the view of the scene camera",
  53. "ViewProjectionMatrixBlock": "A matrix to remap points in 3D space to 2D view space before remapping to 2D screen space",
  54. "WorldMatrixBlock": "A matrix to remap points in 3D local space to 3D world space",
  55. "WorldViewProjectionMatrixBlock": "A matrix to remap points in 3D local space to 3D world space, then to 2D camera space, and ending in 2D screen space",
  56. "ColorBlock": "Outputs the RGBA color of each vertex in the mesh",
  57. "InstancesBlock": "Provides the world matrix for each instance to apply this material to all instances",
  58. "MatrixIndicesBlock": "A Vector4 representing the vertex to bone skinning assignments",
  59. "MatrixWeightsBlock": "A Vector4 representing the vertex to bone skinning weights",
  60. "NormalBlock": "A Vector3 representing the normal of each vertex of the attached mesh",
  61. "PositionBlock": "A Vector3 representing the position of each vertex of the attached mesh",
  62. "TangentBlock": "A Vector3 representing the tangent of each vertex of the attached mesh",
  63. "UVBlock": "A Vector2 representing the UV coordinates of each vertex of the attached mesh",
  64. "WorldNormal": "A Vector4 representing the normal of each vertex of the attached mesh transformed into world space",
  65. "WorldTangent": "A Vector4 representing the tangent of each vertex of the attached mesh transformed into world space",
  66. "PerturbNormalBlock": "Creates high-frequency detail normal vectors based on a normal map, the world position, and world normal",
  67. "NormalBlend": "Outputs the result of blending two normal maps together using a per-channel screen",
  68. "WorldPosition": "A Vector4 representing the position of each vertex of the attached mesh transformed into world space",
  69. "DiscardBlock": "A final node that will not output a pixel below the cutoff value",
  70. "FragmentOutputBlock": "A mandatory final node for outputing the color of each pixel",
  71. "VertexOutputBlock": "A mandatory final node for outputing the position of each vertex",
  72. "ClampBlock": "Outputs values above the maximum or below minimum as maximum or minimum values respectively",
  73. "NormalizeBlock": "Remaps the length of a vector or color to 1",
  74. "RemapBlock": "Remaps input value between sourceMin and sourceMax to a new range between targetMin and targetMax",
  75. "CeilingBlock": "Outputs fractional values as the next higher whole number",
  76. "FloorBlock": "Outputs fractional values as the next lower whole number",
  77. "RoundBlock": "Outputs fractional values rounded to the nearest whole number",
  78. "ModBlock": "Outputs the value of one parameter modulo another",
  79. "CameraPositionBlock": "Outputs a Vector3 position of the active scene camera",
  80. "FogBlock": "Applies fog to the scene with an increasing opacity based on distance from the camera",
  81. "FogColorBlock": "The system value for fog color pulled from the scene",
  82. "ImageProcessingBlock": "Provides access to all of the Babylon image processing properties",
  83. "LightBlock": "Outputs diffuse and specular contributions from one or more scene lights",
  84. "LightInformationBlock": "Provides the direction, color and intensity of a selected light based on its world position",
  85. "ReflectionTextureBlock": "Creates a reflection from the input texture",
  86. "ViewDirectionBlock": "Outputs the direction vector of where the camera is aimed",
  87. "AbsBlock": "Outputs the absolute value of the input value",
  88. "ArcCosBlock": "Outputs the inverse of the cosine value based on the input value",
  89. "ArcSinBlock": "Outputs the inverse of the sine value based on the input value",
  90. "ArcTan2Block": "Outputs the inverse of the tangent value based on the input value",
  91. "ArcTanBlock": "Outputs the inverse of the tangent value based on the input value",
  92. "CosBlock": "Outputs the cosine value based on the input value",
  93. "DegreesToRadiansBlock": "Converts the input degrees value to radians",
  94. "Exp2Block": "Outputs the input value multiplied by itself 1 time. (Exponent of 2)",
  95. "ExpBlock": "Outputs the input value multiplied by itself 9 time. (Exponent of 10)",
  96. "FractBlock": "Outputs only the fractional value of a floating point number",
  97. "LogBlock": "The logarithmic value based on the input value",
  98. "PowBlock": "Outputs the input value multiplied by itself the number of times equal to the power input (Exponent of power)",
  99. "RadiansToDegreesBlock": "Converts the input radians value to degrees",
  100. "SawToothWaveBlock": "Outputs a sawtooth pattern value between -1 and 1 based on the input value",
  101. "SignBlock": "returns 1 if the input is positive, 0 if input is equal to 0, or -1 if the input is negative",
  102. "SinBlock": "Outputs the the sine value based on the input value",
  103. "SqrtBlock": "Outputs the the square root of the input value",
  104. "SquareWaveBlock": "Outputs a stepped pattern value between -1 and 1 based on the input value",
  105. "TanBlock": "Outputs the the tangent value based on the input value",
  106. "TriangleWaveBlock": "Outputs a sawtooth pattern value between 0 and 1 based on the input value",
  107. "CrossBlock": "Outputs a vector that is perpendicular to two input vectors",
  108. "DotBlock": "Outputs the cos of the angle between two vectors",
  109. "FresnelBlock": "Outputs the grazing angle of the surface of the mesh, relative to a camera influenced by the bias and power inputs",
  110. "TransformBlock": "Transforms a input vector based on the input matrix",
  111. "DerivativeBlock": "FRAGMENT SHADER ONLY. Provides the rate of change for an input on a given axis (x,y).",
  112. "DesaturateBlock": "Convert a color input into a grayscale representation.",
  113. "WorldViewMatrixBlock": "A matrix to remap points in 3D local space to 3D world space, and ending in 2D camera space.",
  114. "FrontFacingBlock": "Returns 1 if a mesh triangle faces the normal direction and 0 if it does not.",
  115. "SimplexPerlin3DBlock": "Creates a type of gradient noise with few directional artifacts.",
  116. "WorleyNoise3DBlock": "Creates a random pattern resembling cells.",
  117. "ReflectBlock": "Outputs the direction of the input vector reflected across the surface normal.",
  118. "RefractBlock": "Outputs a direction simulating a deflection of the input vector.",
  119. "Rotate2dBlock": "Rotates UV coordinates around the W axis.",
  120. "PBRMetallicRoughnessBlock": "PBR metallic/roughness material",
  121. "SheenBlock": "PBR Sheen block",
  122. "AmbientOcclusionBlock": "PBR Ambient occlusion block",
  123. "ReflectivityBlock": "PBR Reflectivity block",
  124. "AnisotropyBlock": "PBR Anisotropy block",
  125. "ReflectionBlock": "PBR Reflection block",
  126. "ClearCoatBlock": "PBR ClearCoat block",
  127. "RefractionBlock": "PBR Refraction block",
  128. "SubSurfaceBlock": "PBR SubSurface block",
  129. "Position2DBlock": "A Vector2 representing the position of each vertex of the screen quad",
  130. "CurrentScreenBlock": "The screen buffer used as input for the post process",
  131. "ParticleUVBlock": "The particle uv texture coordinate",
  132. "ParticleTextureBlock": "The particle texture",
  133. "ParticleColorBlock": "The particle color",
  134. "ParticleTextureMaskBlock": "The particle texture mask",
  135. "ParticleRampGradientBlock": "The particle ramp gradient block",
  136. "ParticleBlendMultiplyBlock": "The particle blend multiply block",
  137. };
  138. constructor(props: INodeListComponentProps) {
  139. super(props);
  140. this.state = { filter: "" };
  141. this._onResetRequiredObserver = this.props.globalState.onResetRequiredObservable.add(() => {
  142. this.forceUpdate();
  143. });
  144. }
  145. componentWillUnmount() {
  146. this.props.globalState.onResetRequiredObservable.remove(this._onResetRequiredObserver);
  147. }
  148. filterContent(filter: string) {
  149. this.setState({ filter: filter });
  150. }
  151. render() {
  152. // Block types used to create the menu from
  153. const allBlocks = {
  154. Animation: ["BonesBlock", "MorphTargetsBlock"],
  155. Color_Management: ["ReplaceColorBlock", "PosterizeBlock", "GradientBlock", "DesaturateBlock"],
  156. Conversion_Blocks: ["ColorMergerBlock", "ColorSplitterBlock", "VectorMergerBlock", "VectorSplitterBlock"],
  157. Inputs: ["Float", "Vector2", "Vector3", "Vector4", "Color3", "Color4", "TextureBlock", "ReflectionTextureBlock", "TimeBlock", "DeltaTimeBlock"],
  158. Interpolation: ["LerpBlock", "StepBlock", "SmoothStepBlock", "NLerpBlock"],
  159. Math__Standard: ["AddBlock", "DivideBlock", "MaxBlock", "MinBlock", "ModBlock", "MultiplyBlock", "NegateBlock", "OneMinusBlock", "ReciprocalBlock", "ScaleBlock", "SignBlock", "SqrtBlock", "SubtractBlock"],
  160. Math__Scientific: ["AbsBlock", "ArcCosBlock", "ArcSinBlock", "ArcTanBlock", "ArcTan2Block", "CosBlock", "DegreesToRadiansBlock", "ExpBlock", "Exp2Block", "FractBlock", "LogBlock", "PowBlock", "RadiansToDegreesBlock", "SawToothWaveBlock", "SinBlock", "SquareWaveBlock", "TanBlock", "TriangleWaveBlock"],
  161. Math__Vector: ["CrossBlock", "DerivativeBlock", "DistanceBlock", "DotBlock", "FresnelBlock", "LengthBlock", "ReflectBlock", "RefractBlock", "Rotate2dBlock", "TransformBlock", ],
  162. Matrices: ["Matrix", "WorldMatrixBlock", "WorldViewMatrixBlock", "WorldViewProjectionMatrixBlock", "ViewMatrixBlock", "ViewProjectionMatrixBlock", "ProjectionMatrixBlock"],
  163. Mesh: ["InstancesBlock", "PositionBlock", "UVBlock", "ColorBlock", "NormalBlock", "PerturbNormalBlock", "NormalBlendBlock" , "TangentBlock", "MatrixIndicesBlock", "MatrixWeightsBlock", "WorldPositionBlock", "WorldNormalBlock", "WorldTangentBlock", "FrontFacingBlock"],
  164. Noises: ["RandomNumberBlock", "SimplexPerlin3DBlock", "WorleyNoise3DBlock"],
  165. Output_Nodes: ["VertexOutputBlock", "FragmentOutputBlock", "DiscardBlock"],
  166. Particle: ["ParticleBlendMultiplyBlock", "ParticleColorBlock", "ParticleRampGradientBlock", "ParticleTextureBlock", "ParticleTextureMaskBlock", "ParticleUVBlock"],
  167. PBR: ["PBRMetallicRoughnessBlock", "AmbientOcclusionBlock", "AnisotropyBlock", "ClearCoatBlock", "ReflectionBlock", "ReflectivityBlock", "RefractionBlock", "SheenBlock", "SubSurfaceBlock"],
  168. PostProcess: ["Position2DBlock", "CurrentScreenBlock"],
  169. Range: ["ClampBlock", "RemapBlock", "NormalizeBlock"],
  170. Round: ["RoundBlock", "CeilingBlock", "FloorBlock"],
  171. Scene: ["FogBlock", "CameraPositionBlock", "FogColorBlock", "ImageProcessingBlock", "LightBlock", "LightInformationBlock", "ViewDirectionBlock"],
  172. };
  173. switch (this.props.globalState.mode) {
  174. case NodeMaterialModes.Material:
  175. delete allBlocks["PostProcess"];
  176. delete allBlocks["Particle"];
  177. break;
  178. case NodeMaterialModes.PostProcess:
  179. delete allBlocks["Animation"];
  180. delete allBlocks["Mesh"];
  181. delete allBlocks["Particle"];
  182. break;
  183. case NodeMaterialModes.Particle:
  184. delete allBlocks["Animation"];
  185. delete allBlocks["Mesh"];
  186. delete allBlocks["PostProcess"];
  187. allBlocks.Output_Nodes.splice(allBlocks.Output_Nodes.indexOf("VertexOutputBlock"), 1);
  188. break;
  189. }
  190. // Create node menu
  191. var blockMenu = [];
  192. for (var key in allBlocks) {
  193. var blockList = (allBlocks as any)[key].filter((b: string) => !this.state.filter || b.toLowerCase().indexOf(this.state.filter.toLowerCase()) !== -1)
  194. .sort((a: string, b: string) => a.localeCompare(b))
  195. .map((block: any, i: number) => {
  196. let tooltip = NodeListComponent._Tooltips[block] || "";
  197. return <DraggableLineComponent key={block} data={block} tooltip={tooltip}/>;
  198. });
  199. if (blockList.length) {
  200. blockMenu.push(
  201. <LineContainerComponent key={key + " blocks"} title={key.replace("__", ": ").replace("_", " ")} closed={false}>
  202. {blockList}
  203. </LineContainerComponent>
  204. );
  205. }
  206. }
  207. return (
  208. <div id="nodeList">
  209. <div className="panes">
  210. <div className="pane">
  211. <div className="filter">
  212. <input type="text" placeholder="Filter"
  213. onFocus={() => this.props.globalState.blockKeyboardEvents = true}
  214. onBlur={(evt) => {
  215. this.props.globalState.blockKeyboardEvents = false;
  216. }}
  217. onChange={(evt) => this.filterContent(evt.target.value)} />
  218. </div>
  219. <div className="list-container">
  220. {blockMenu}
  221. </div>
  222. </div>
  223. </div>
  224. </div>
  225. );
  226. }
  227. }