nodeMaterialBuildStateSharedData.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. * Build Id used to avoid multiple recompilations
  33. */
  34. public buildId: number;
  35. /** List of emitted variables */
  36. public variableNames: { [key: string]: number } = {};
  37. /** List of emitted defines */
  38. public defineNames: { [key: string]: number } = {};
  39. /** Should emit comments? */
  40. public emitComments: boolean;
  41. /** Emit build activity */
  42. public verbose: boolean;
  43. /**
  44. * Gets the compilation hints emitted at compilation time
  45. */
  46. public hints = {
  47. needWorldViewMatrix: false,
  48. needWorldViewProjectionMatrix: false,
  49. needAlphaBlending: false,
  50. needAlphaTesting: false
  51. };
  52. /**
  53. * List of compilation checks
  54. */
  55. public checks = {
  56. emitVertex: false,
  57. emitFragment: false,
  58. notConnectedNonOptionalInputs: new Array<NodeMaterialConnectionPoint>()
  59. };
  60. /** Creates a new shared data */
  61. public constructor() {
  62. // Exclude usual attributes from free variable names
  63. this.variableNames["position"] = 0;
  64. this.variableNames["normal"] = 0;
  65. this.variableNames["tangent"] = 0;
  66. this.variableNames["uv"] = 0;
  67. this.variableNames["uv2"] = 0;
  68. this.variableNames["uv3"] = 0;
  69. this.variableNames["uv4"] = 0;
  70. this.variableNames["uv4"] = 0;
  71. this.variableNames["uv5"] = 0;
  72. this.variableNames["uv6"] = 0;
  73. this.variableNames["color"] = 0;
  74. this.variableNames["matricesIndices"] = 0;
  75. this.variableNames["matricesWeights"] = 0;
  76. this.variableNames["matricesIndicesExtra"] = 0;
  77. this.variableNames["matricesWeightsExtra"] = 0;
  78. // Exclude defines
  79. this.defineNames["MAINUV0"] = 0;
  80. this.defineNames["MAINUV1"] = 0;
  81. this.defineNames["MAINUV2"] = 0;
  82. this.defineNames["MAINUV3"] = 0;
  83. this.defineNames["MAINUV4"] = 0;
  84. this.defineNames["MAINUV5"] = 0;
  85. this.defineNames["MAINUV6"] = 0;
  86. this.defineNames["MAINUV7"] = 0;
  87. }
  88. /**
  89. * Emits console errors and exceptions if there is a failing check
  90. */
  91. public emitErrors() {
  92. let shouldThrowError = false;
  93. if (!this.checks.emitVertex) {
  94. shouldThrowError = true;
  95. console.error("NodeMaterial does not have a vertex output. You need to at least add a block that generates a glPosition value.");
  96. }
  97. if (!this.checks.emitFragment) {
  98. shouldThrowError = true;
  99. console.error("NodeMaterial does not have a fragment output. You need to at least add a block that generates a glFragColor value.");
  100. }
  101. for (var notConnectedInput of this.checks.notConnectedNonOptionalInputs) {
  102. shouldThrowError = true;
  103. console.error(`input ${notConnectedInput.name} from block ${notConnectedInput.ownerBlock.name}[${notConnectedInput.ownerBlock.getClassName()}] is not connected and is not optional.`);
  104. }
  105. if (shouldThrowError) {
  106. throw "Build of NodeMaterial failed.";
  107. }
  108. }
  109. }