UNPKG

@babylonjs/core

Version:

Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.

171 lines 6.41 kB
import { Logger } from "../../Misc/logger.js"; /** * Class used to store shared data between 2 NodeMaterialBuildState */ export class NodeMaterialBuildStateSharedData { /** Creates a new shared data */ constructor() { /** * Gets the list of emitted varyings */ this.temps = []; /** * Gets the list of emitted varyings */ this.varyings = []; /** * Gets the varying declaration string (for vertex shader) */ this.varyingDeclaration = ""; /** * Gets the varying declaration string (for fragment shader) * This is potentially different from varyingDeclaration only in WebGPU */ this.varyingDeclarationFragment = ""; /** * Gets the varying initialization string (for fragment shader) * Only used in WebGPU, to reconstruct the varying values from the vertex shader if their types is mat4x4f */ this.varyingInitializationsFragment = ""; /** * Input blocks */ this.inputBlocks = []; /** * Input blocks */ this.textureBlocks = []; /** * Bindable blocks (Blocks that need to set data to the effect) */ this.bindableBlocks = []; /** * 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 */ this.forcedBindableBlocks = []; /** * List of blocks that can provide a compilation fallback */ this.blocksWithFallbacks = []; /** * List of blocks that can provide a define update */ this.blocksWithDefines = []; /** * List of blocks that can provide a repeatable content */ this.repeatableContentBlocks = []; /** * List of blocks that can provide a dynamic list of uniforms */ this.dynamicUniformBlocks = []; /** * List of blocks that can block the isReady function for the material */ this.blockingBlocks = []; /** * Gets the list of animated inputs */ this.animatedInputs = []; /** * Configurations used to format the generated code */ this.formatConfig = { getUniformAnnotation: null, formatVariablename: (name) => name.replace(/[^a-zA-Z_]+/g, ""), }; /** List of emitted variables */ this.variableNames = {}; /** List of emitted defines */ this.defineNames = {}; /** * Gets the compilation hints emitted at compilation time */ this.hints = { needWorldViewMatrix: false, needWorldViewProjectionMatrix: false, needAlphaBlending: false, needAlphaTesting: false, }; /** * List of compilation checks */ this.checks = { emitVertex: false, emitFragment: false, notConnectedNonOptionalInputs: new Array(), customErrors: new Array(), }; /** * Is vertex program allowed to be empty? */ this.allowEmptyVertexProgram = false; // Exclude usual attributes from free variable names this.variableNames["position"] = 0; this.variableNames["normal"] = 0; this.variableNames["tangent"] = 0; this.variableNames["uv"] = 0; this.variableNames["uv2"] = 0; this.variableNames["uv3"] = 0; this.variableNames["uv4"] = 0; this.variableNames["uv5"] = 0; this.variableNames["uv6"] = 0; this.variableNames["color"] = 0; this.variableNames["matricesIndices"] = 0; this.variableNames["matricesWeights"] = 0; this.variableNames["matricesIndicesExtra"] = 0; this.variableNames["matricesWeightsExtra"] = 0; this.variableNames["diffuseBase"] = 0; this.variableNames["specularBase"] = 0; this.variableNames["worldPos"] = 0; this.variableNames["shadow"] = 0; this.variableNames["view"] = 0; // Exclude known varyings this.variableNames["vTBN"] = 0; // Exclude defines this.defineNames["MAINUV0"] = 0; this.defineNames["MAINUV1"] = 0; this.defineNames["MAINUV2"] = 0; this.defineNames["MAINUV3"] = 0; this.defineNames["MAINUV4"] = 0; this.defineNames["MAINUV5"] = 0; this.defineNames["MAINUV6"] = 0; this.defineNames["MAINUV7"] = 0; } /** * Push a new error to the build state, avoiding exceptions that can break the build process * @param message defines the error message to push */ raiseBuildError(message) { if (this.checks.customErrors.indexOf(message) !== -1) { this.checks.customErrors.push(message); } } /** * Emits console errors and exceptions if there is a failing check * @returns true if all checks pass */ emitErrors() { let errorMessage = ""; if (!this.checks.emitVertex && !this.allowEmptyVertexProgram) { errorMessage += "NodeMaterial does not have a vertex output. You need to at least add a block that generates a position value.\n"; } if (!this.checks.emitFragment) { errorMessage += "NodeMaterial does not have a fragment output. You need to at least add a block that generates a color value.\n"; } for (const notConnectedInput of this.checks.notConnectedNonOptionalInputs) { errorMessage += `input ${notConnectedInput.name} from block ${notConnectedInput.ownerBlock.name}[${notConnectedInput.ownerBlock.getClassName()}] is not connected and is not optional.\n`; } for (const customError of this.checks.customErrors) { errorMessage += customError + "\n"; } if (errorMessage) { errorMessage = "Node material build failed: \n" + errorMessage; Logger.Error(errorMessage); this.nodeMaterial.onBuildErrorObservable.notifyObservers(errorMessage); return false; } return true; } } //# sourceMappingURL=nodeMaterialBuildStateSharedData.js.map