blockTools.ts 7.3 KB

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