blockTools.ts 6.8 KB

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