nodeMaterialBuildStateSharedData.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * Class used to store shared data between 2 NodeMaterialBuildState
  3. */
  4. export class NodeMaterialBuildStateSharedData {
  5. /** Creates a new shared data */
  6. constructor() {
  7. /**
  8. * Gets the list of emitted varyings
  9. */
  10. this.temps = [];
  11. /**
  12. * Gets the list of emitted varyings
  13. */
  14. this.varyings = [];
  15. /**
  16. * Gets the varying declaration string
  17. */
  18. this.varyingDeclaration = "";
  19. /**
  20. * Input blocks
  21. */
  22. this.inputBlocks = [];
  23. /**
  24. * Input blocks
  25. */
  26. this.textureBlocks = [];
  27. /**
  28. * Bindable blocks (Blocks that need to set data to the effect)
  29. */
  30. this.bindableBlocks = [];
  31. /**
  32. * Bindable blocks (Blocks that need to set data to the effect) that will always be called (by bindForSubMesh), contrary to bindableBlocks that won't be called if _mustRebind() returns false
  33. */
  34. this.forcedBindableBlocks = [];
  35. /**
  36. * List of blocks that can provide a compilation fallback
  37. */
  38. this.blocksWithFallbacks = [];
  39. /**
  40. * List of blocks that can provide a define update
  41. */
  42. this.blocksWithDefines = [];
  43. /**
  44. * List of blocks that can provide a repeatable content
  45. */
  46. this.repeatableContentBlocks = [];
  47. /**
  48. * List of blocks that can provide a dynamic list of uniforms
  49. */
  50. this.dynamicUniformBlocks = [];
  51. /**
  52. * List of blocks that can block the isReady function for the material
  53. */
  54. this.blockingBlocks = [];
  55. /**
  56. * Gets the list of animated inputs
  57. */
  58. this.animatedInputs = [];
  59. /** List of emitted variables */
  60. this.variableNames = {};
  61. /** List of emitted defines */
  62. this.defineNames = {};
  63. /**
  64. * Gets the compilation hints emitted at compilation time
  65. */
  66. this.hints = {
  67. needWorldViewMatrix: false,
  68. needWorldViewProjectionMatrix: false,
  69. needAlphaBlending: false,
  70. needAlphaTesting: false,
  71. };
  72. /**
  73. * List of compilation checks
  74. */
  75. this.checks = {
  76. emitVertex: false,
  77. emitFragment: false,
  78. notConnectedNonOptionalInputs: new Array(),
  79. };
  80. /**
  81. * Is vertex program allowed to be empty?
  82. */
  83. this.allowEmptyVertexProgram = false;
  84. // Exclude usual attributes from free variable names
  85. this.variableNames["position"] = 0;
  86. this.variableNames["normal"] = 0;
  87. this.variableNames["tangent"] = 0;
  88. this.variableNames["uv"] = 0;
  89. this.variableNames["uv2"] = 0;
  90. this.variableNames["uv3"] = 0;
  91. this.variableNames["uv4"] = 0;
  92. this.variableNames["uv5"] = 0;
  93. this.variableNames["uv6"] = 0;
  94. this.variableNames["color"] = 0;
  95. this.variableNames["matricesIndices"] = 0;
  96. this.variableNames["matricesWeights"] = 0;
  97. this.variableNames["matricesIndicesExtra"] = 0;
  98. this.variableNames["matricesWeightsExtra"] = 0;
  99. this.variableNames["diffuseBase"] = 0;
  100. this.variableNames["specularBase"] = 0;
  101. this.variableNames["worldPos"] = 0;
  102. this.variableNames["shadow"] = 0;
  103. this.variableNames["view"] = 0;
  104. // Exclude known varyings
  105. this.variableNames["vTBN"] = 0;
  106. // Exclude defines
  107. this.defineNames["MAINUV0"] = 0;
  108. this.defineNames["MAINUV1"] = 0;
  109. this.defineNames["MAINUV2"] = 0;
  110. this.defineNames["MAINUV3"] = 0;
  111. this.defineNames["MAINUV4"] = 0;
  112. this.defineNames["MAINUV5"] = 0;
  113. this.defineNames["MAINUV6"] = 0;
  114. this.defineNames["MAINUV7"] = 0;
  115. }
  116. /**
  117. * Emits console errors and exceptions if there is a failing check
  118. */
  119. emitErrors() {
  120. let errorMessage = "";
  121. if (!this.checks.emitVertex && !this.allowEmptyVertexProgram) {
  122. errorMessage += "NodeMaterial does not have a vertex output. You need to at least add a block that generates a glPosition value.\n";
  123. }
  124. if (!this.checks.emitFragment) {
  125. errorMessage += "NodeMaterial does not have a fragment output. You need to at least add a block that generates a glFragColor value.\n";
  126. }
  127. for (const notConnectedInput of this.checks.notConnectedNonOptionalInputs) {
  128. errorMessage += `input ${notConnectedInput.name} from block ${notConnectedInput.ownerBlock.name}[${notConnectedInput.ownerBlock.getClassName()}] is not connected and is not optional.\n`;
  129. }
  130. if (errorMessage) {
  131. // eslint-disable-next-line no-throw-literal
  132. throw "Build of NodeMaterial failed:\n" + errorMessage;
  133. }
  134. }
  135. }
  136. //# sourceMappingURL=nodeMaterialBuildStateSharedData.js.map