nodeMaterialBuildStateSharedData.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { NodeMaterialConnectionPoint } from './nodeMaterialBlockConnectionPoint';
  2. import { NodeMaterialBlock } from './nodeMaterialBlock';
  3. /**
  4. * Class used to store shared data between 2 NodeMaterialBuildState
  5. */
  6. export class NodeMaterialBuildStateSharedData {
  7. /**
  8. * Gets the list of emitted varyings
  9. */
  10. public varyings = new Array<string>();
  11. /**
  12. * Gets the varying declaration string
  13. */
  14. public varyingDeclaration = "";
  15. /**
  16. * Uniform connection points
  17. */
  18. public uniformConnectionPoints = new Array<NodeMaterialConnectionPoint>();
  19. /**
  20. * Bindable blocks (Blocks that need to set data to the effect)
  21. */
  22. public bindableBlocks = new Array<NodeMaterialBlock>();
  23. /**
  24. * List of blocks that can provide a compilation fallback
  25. */
  26. public blocksWithFallbacks = new Array<NodeMaterialBlock>();
  27. /**
  28. * List of blocks that can provide a define update
  29. */
  30. public blocksWithDefines = new Array<NodeMaterialBlock>();
  31. /**
  32. * List of blocks that can provide a repeatable content
  33. */
  34. public repeatableContentBlocks = new Array<NodeMaterialBlock>();
  35. /**
  36. * List of blocks that can block the isReady function for the material
  37. */
  38. public blockingBlocks = new Array<NodeMaterialBlock>();
  39. /**
  40. * Build Id used to avoid multiple recompilations
  41. */
  42. public buildId: number;
  43. /** List of emitted variables */
  44. public variableNames: { [key: string]: number } = {};
  45. /** List of emitted defines */
  46. public defineNames: { [key: string]: number } = {};
  47. /** Should emit comments? */
  48. public emitComments: boolean;
  49. /** Emit build activity */
  50. public verbose: boolean;
  51. /**
  52. * Gets the compilation hints emitted at compilation time
  53. */
  54. public hints = {
  55. needWorldViewMatrix: false,
  56. needWorldViewProjectionMatrix: false,
  57. needAlphaBlending: false,
  58. needAlphaTesting: false
  59. };
  60. /**
  61. * List of compilation checks
  62. */
  63. public checks = {
  64. emitVertex: false,
  65. emitFragment: false,
  66. notConnectedNonOptionalInputs: new Array<NodeMaterialConnectionPoint>()
  67. };
  68. /** Creates a new shared data */
  69. public constructor() {
  70. // Exclude usual attributes from free variable names
  71. this.variableNames["position"] = 0;
  72. this.variableNames["normal"] = 0;
  73. this.variableNames["tangent"] = 0;
  74. this.variableNames["uv"] = 0;
  75. this.variableNames["uv2"] = 0;
  76. this.variableNames["uv3"] = 0;
  77. this.variableNames["uv4"] = 0;
  78. this.variableNames["uv4"] = 0;
  79. this.variableNames["uv5"] = 0;
  80. this.variableNames["uv6"] = 0;
  81. this.variableNames["color"] = 0;
  82. this.variableNames["matricesIndices"] = 0;
  83. this.variableNames["matricesWeights"] = 0;
  84. this.variableNames["matricesIndicesExtra"] = 0;
  85. this.variableNames["matricesWeightsExtra"] = 0;
  86. // Exclude defines
  87. this.defineNames["MAINUV0"] = 0;
  88. this.defineNames["MAINUV1"] = 0;
  89. this.defineNames["MAINUV2"] = 0;
  90. this.defineNames["MAINUV3"] = 0;
  91. this.defineNames["MAINUV4"] = 0;
  92. this.defineNames["MAINUV5"] = 0;
  93. this.defineNames["MAINUV6"] = 0;
  94. this.defineNames["MAINUV7"] = 0;
  95. }
  96. /**
  97. * Emits console errors and exceptions if there is a failing check
  98. */
  99. public emitErrors() {
  100. let shouldThrowError = false;
  101. if (!this.checks.emitVertex) {
  102. shouldThrowError = true;
  103. console.error("NodeMaterial does not have a vertex output. You need to at least add a block that generates a glPosition value.");
  104. }
  105. if (!this.checks.emitFragment) {
  106. shouldThrowError = true;
  107. console.error("NodeMaterial does not have a fragment output. You need to at least add a block that generates a glFragColor value.");
  108. }
  109. for (var notConnectedInput of this.checks.notConnectedNonOptionalInputs) {
  110. shouldThrowError = true;
  111. console.error(`input ${notConnectedInput.name} from block ${notConnectedInput.ownerBlock.name}[${notConnectedInput.ownerBlock.getClassName()}] is not connected and is not optional.`);
  112. }
  113. if (shouldThrowError) {
  114. throw "Build of NodeMaterial failed.";
  115. }
  116. }
  117. }