inputDisplayManager.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { IDisplayManager } from './displayManager';
  2. import { NodeMaterialBlock } from 'babylonjs/Materials/Node/nodeMaterialBlock';
  3. import { InputBlock } from 'babylonjs/Materials/Node/Blocks/Input/inputBlock';
  4. import { NodeMaterialSystemValues } from 'babylonjs/Materials/Node/Enums/nodeMaterialSystemValues';
  5. import { NodeMaterialBlockConnectionPointTypes } from 'babylonjs/Materials/Node/Enums/nodeMaterialBlockConnectionPointTypes';
  6. import { AnimatedInputBlockTypes } from 'babylonjs/Materials/Node/Blocks/Input/animatedInputBlockTypes';
  7. import { Vector2, Vector3, Vector4 } from 'babylonjs/Maths/math.vector';
  8. import { Color3 } from 'babylonjs/Maths/math.color';
  9. import { BlockTools } from '../../blockTools';
  10. import { StringTools } from '../../stringTools';
  11. export class InputDisplayManager implements IDisplayManager {
  12. public getHeaderClass(block: NodeMaterialBlock) {
  13. let inputBlock = block as InputBlock;
  14. if (inputBlock.isConstant) {
  15. return "constant"
  16. }
  17. if (inputBlock.visibleInInspector) {
  18. return "inspector"
  19. }
  20. return "";
  21. }
  22. public shouldDisplayPortLabels(block: NodeMaterialBlock): boolean {
  23. return false;
  24. }
  25. public getHeaderText(block: NodeMaterialBlock): string {
  26. let inputBlock = block as InputBlock;
  27. let name = `${inputBlock.name} (${StringTools.GetBaseType(inputBlock.output.type)})`;
  28. if (inputBlock.isAttribute) {
  29. name = StringTools.GetBaseType(inputBlock.output.type);
  30. }
  31. return name;
  32. }
  33. public getBackgroundColor(block: NodeMaterialBlock): string {
  34. let color = "";
  35. let inputBlock = block as InputBlock;
  36. switch (inputBlock.type) {
  37. case NodeMaterialBlockConnectionPointTypes.Color3:
  38. case NodeMaterialBlockConnectionPointTypes.Color4: {
  39. if (inputBlock.value) {
  40. color = (inputBlock.value as Color3).toHexString();
  41. break;
  42. }
  43. }
  44. default:
  45. color = BlockTools.GetColorFromConnectionNodeType(inputBlock.type);
  46. break;
  47. }
  48. return color;
  49. }
  50. public updatePreviewContent(block: NodeMaterialBlock, contentArea: HTMLDivElement): void {
  51. let value = "";
  52. let inputBlock = block as InputBlock;
  53. let isFat = false;
  54. let smallFont = false;
  55. if (inputBlock.isAttribute) {
  56. value = "mesh." + inputBlock.name;
  57. } else if (inputBlock.isSystemValue) {
  58. switch (inputBlock.systemValue) {
  59. case NodeMaterialSystemValues.World:
  60. value = "World";
  61. break;
  62. case NodeMaterialSystemValues.WorldView:
  63. value = "World x View";
  64. break;
  65. case NodeMaterialSystemValues.WorldViewProjection:
  66. value = "World x View x Projection";
  67. isFat = true;
  68. break;
  69. case NodeMaterialSystemValues.View:
  70. value = "View";
  71. break;
  72. case NodeMaterialSystemValues.ViewProjection:
  73. value = "View x Projection";
  74. break;
  75. case NodeMaterialSystemValues.Projection:
  76. value = "Projection";
  77. break;
  78. case NodeMaterialSystemValues.CameraPosition:
  79. value = "Camera position";
  80. break;
  81. case NodeMaterialSystemValues.FogColor:
  82. value = "Fog color";
  83. break;
  84. case NodeMaterialSystemValues.DeltaTime:
  85. value = "Delta time";
  86. break;
  87. }
  88. } else {
  89. switch (inputBlock.type) {
  90. case NodeMaterialBlockConnectionPointTypes.Float:
  91. if (inputBlock.animationType !== AnimatedInputBlockTypes.None) {
  92. value = AnimatedInputBlockTypes[inputBlock.animationType];
  93. } else {
  94. value = inputBlock.value.toFixed(2);
  95. }
  96. break;
  97. case NodeMaterialBlockConnectionPointTypes.Vector2:
  98. let vec2Value = inputBlock.value as Vector2
  99. value = `(${vec2Value.x.toFixed(2)}, ${vec2Value.y.toFixed(2)})`;
  100. break;
  101. case NodeMaterialBlockConnectionPointTypes.Vector3:
  102. let vec3Value = inputBlock.value as Vector3
  103. value = `(${vec3Value.x.toFixed(2)}, ${vec3Value.y.toFixed(2)}, ${vec3Value.z.toFixed(2)})`;
  104. break;
  105. case NodeMaterialBlockConnectionPointTypes.Vector4:
  106. smallFont = true;
  107. let vec4Value = inputBlock.value as Vector4
  108. value = `(${vec4Value.x.toFixed(2)}, ${vec4Value.y.toFixed(2)}, ${vec4Value.z.toFixed(2)}, ${vec4Value.w.toFixed(2)})`;
  109. break;
  110. }
  111. }
  112. contentArea.innerHTML = value;
  113. contentArea.classList.add("input-block");
  114. if (isFat) {
  115. contentArea.classList.add("fat");
  116. }
  117. if (smallFont) {
  118. contentArea.classList.add("small-font");
  119. }
  120. }
  121. }