blockTools.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import { AlphaTestBlock } from 'babylonjs/Materials/Node/Blocks/Fragment/alphaTestBlock';
  2. import { BonesBlock } from 'babylonjs/Materials/Node/Blocks/Vertex/bonesBlock';
  3. import { InstancesBlock } from 'babylonjs/Materials/Node/Blocks/Vertex/instancesBlock';
  4. import { MorphTargetsBlock } from 'babylonjs/Materials/Node/Blocks/Vertex/morphTargetsBlock';
  5. import { ImageProcessingBlock } from 'babylonjs/Materials/Node/Blocks/Fragment/imageProcessingBlock';
  6. import { ColorMergerBlock } from 'babylonjs/Materials/Node/Blocks/colorMergerBlock';
  7. import { VectorMergerBlock } from 'babylonjs/Materials/Node/Blocks/vectorMergerBlock';
  8. import { ColorSplitterBlock } from 'babylonjs/Materials/Node/Blocks/colorSplitterBlock';
  9. import { VectorSplitterBlock } from 'babylonjs/Materials/Node/Blocks/vectorSplitterBlock';
  10. import { TextureBlock } from 'babylonjs/Materials/Node/Blocks/Dual/textureBlock';
  11. import { LightBlock } from 'babylonjs/Materials/Node/Blocks/Dual/lightBlock';
  12. import { FogBlock } from 'babylonjs/Materials/Node/Blocks/Dual/fogBlock';
  13. import { VertexOutputBlock } from 'babylonjs/Materials/Node/Blocks/Vertex/vertexOutputBlock';
  14. import { FragmentOutputBlock } from 'babylonjs/Materials/Node/Blocks/Fragment/fragmentOutputBlock';
  15. import { AddBlock } from 'babylonjs/Materials/Node/Blocks/addBlock';
  16. import { ClampBlock } from 'babylonjs/Materials/Node/Blocks/clampBlock';
  17. import { CrossBlock } from 'babylonjs/Materials/Node/Blocks/crossBlock';
  18. import { DotBlock } from 'babylonjs/Materials/Node/Blocks/dotBlock';
  19. import { MultiplyBlock } from 'babylonjs/Materials/Node/Blocks/multiplyBlock';
  20. import { TransformBlock } from 'babylonjs/Materials/Node/Blocks/transformBlock';
  21. import { NodeMaterialBlockConnectionPointTypes } from 'babylonjs/Materials/Node/nodeMaterialBlockConnectionPointTypes';
  22. export class BlockTools {
  23. public static GetBlockFromString(data: string) {
  24. switch (data) {
  25. case "BonesBlock":
  26. return new BonesBlock("Bones");
  27. case "InstancesBlock":
  28. return new InstancesBlock("Instances");
  29. case "MorphTargetsBlock":
  30. return new MorphTargetsBlock("MorphTargets");
  31. case "AlphaTestBlock":
  32. return new AlphaTestBlock("AlphaTest");
  33. case "ImageProcessingBlock":
  34. return new ImageProcessingBlock("ImageProcessing");
  35. case "ColorMergerBlock":
  36. return new ColorMergerBlock("ColorMerger");
  37. case "VectorMergerBlock":
  38. return new VectorMergerBlock("VectorMerger");
  39. case "ColorSplitterBlock":
  40. return new ColorSplitterBlock("ColorSplitter");
  41. case "VectorSplitterBlock":
  42. return new VectorSplitterBlock("VectorSplitter");
  43. case "TextureBlock":
  44. return new TextureBlock("Texture");
  45. case "LightBlock":
  46. return new LightBlock("Lights");
  47. case "FogBlock":
  48. return new FogBlock("Fog");
  49. case "VertexOutputBlock":
  50. return new VertexOutputBlock("VertexOutput");
  51. case "FragmentOutputBlock":
  52. return new FragmentOutputBlock("FragmentOutput");
  53. case "AddBlock":
  54. return new AddBlock("Add");
  55. case "ClampBlock":
  56. return new ClampBlock("Clamp");
  57. case "CrossBlock":
  58. return new CrossBlock("Dot");
  59. case "DotBlock":
  60. return new DotBlock("Dot");
  61. case "MultiplyBlock":
  62. return new MultiplyBlock("Multiply");
  63. case "TransformBlock":
  64. return new TransformBlock("Transform");
  65. }
  66. return null;
  67. }
  68. public static GetColorFromConnectionNodeType(type: NodeMaterialBlockConnectionPointTypes) {
  69. let color = "Red";
  70. switch (type) {
  71. case NodeMaterialBlockConnectionPointTypes.Float:
  72. color = "DimGrey";
  73. break;
  74. case NodeMaterialBlockConnectionPointTypes.Vector2:
  75. color = "Chocolate";
  76. break;
  77. case NodeMaterialBlockConnectionPointTypes.Vector3:
  78. color = "Crimson";
  79. break;
  80. case NodeMaterialBlockConnectionPointTypes.Vector4:
  81. color = "DarkMagenta";
  82. break;
  83. case NodeMaterialBlockConnectionPointTypes.Color3:
  84. color = "ForestGreen";
  85. break;
  86. case NodeMaterialBlockConnectionPointTypes.Color4:
  87. color = "Gold";
  88. break;
  89. case NodeMaterialBlockConnectionPointTypes.Matrix:
  90. color = "LightCoral";
  91. break;
  92. }
  93. return color;
  94. }
  95. public static GetConnectionNodeTypeFromString(type: string) {
  96. switch (type) {
  97. case "Float":
  98. return NodeMaterialBlockConnectionPointTypes.Float;
  99. case "Vector2":
  100. return NodeMaterialBlockConnectionPointTypes.Vector2;
  101. case "Vector3":
  102. return NodeMaterialBlockConnectionPointTypes.Vector3;
  103. case "Vector4":
  104. return NodeMaterialBlockConnectionPointTypes.Vector4;
  105. case "Matrix":
  106. return NodeMaterialBlockConnectionPointTypes.Matrix;
  107. case "Color3":
  108. return NodeMaterialBlockConnectionPointTypes.Color3;
  109. case "Color4":
  110. return NodeMaterialBlockConnectionPointTypes.Color4;
  111. }
  112. return NodeMaterialBlockConnectionPointTypes.AutoDetect;
  113. }
  114. public static GetStringFromConnectionNodeType(type: NodeMaterialBlockConnectionPointTypes) {
  115. switch (type){
  116. case NodeMaterialBlockConnectionPointTypes.Float:
  117. return "Float";
  118. case NodeMaterialBlockConnectionPointTypes.Vector2:
  119. return "Vector2";
  120. case NodeMaterialBlockConnectionPointTypes.Vector3:
  121. return "Vector3";
  122. case NodeMaterialBlockConnectionPointTypes.Vector4:
  123. return "Vector4";
  124. case NodeMaterialBlockConnectionPointTypes.Color3:
  125. return "Color3";
  126. case NodeMaterialBlockConnectionPointTypes.Color4:
  127. return "Color4";
  128. case NodeMaterialBlockConnectionPointTypes.Matrix:
  129. return "Matrix";
  130. }
  131. return "";
  132. }
  133. }