nodeMaterialBuildStateSharedData.ts 3.7 KB

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