blockTools.ts 6.9 KB

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