1 |
- {"ast":null,"code":"import { NodeMaterialBlock } from \"../nodeMaterialBlock.js\";\nimport { NodeMaterialBlockConnectionPointTypes } from \"../Enums/nodeMaterialBlockConnectionPointTypes.js\";\nimport { NodeMaterialBlockTargets } from \"../Enums/nodeMaterialBlockTargets.js\";\nimport { RegisterClass } from \"../../../Misc/typeStore.js\";\n/**\n * block used to Generate a Voronoi Noise Pattern\n */\nexport class VoronoiNoiseBlock extends NodeMaterialBlock {\n /**\n * Creates a new VoronoiNoiseBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.Neutral);\n this.registerInput(\"seed\", NodeMaterialBlockConnectionPointTypes.Vector2);\n this.registerInput(\"offset\", NodeMaterialBlockConnectionPointTypes.Float);\n this.registerInput(\"density\", NodeMaterialBlockConnectionPointTypes.Float);\n this.registerOutput(\"output\", NodeMaterialBlockConnectionPointTypes.Float);\n this.registerOutput(\"cells\", NodeMaterialBlockConnectionPointTypes.Float);\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"VoronoiNoiseBlock\";\n }\n /**\n * Gets the seed input component\n */\n get seed() {\n return this._inputs[0];\n }\n /**\n * Gets the offset input component\n */\n get offset() {\n return this._inputs[1];\n }\n /**\n * Gets the density input component\n */\n get density() {\n return this._inputs[2];\n }\n /**\n * Gets the output component\n */\n get output() {\n return this._outputs[0];\n }\n /**\n * Gets the output component\n */\n get cells() {\n return this._outputs[1];\n }\n _buildBlock(state) {\n super._buildBlock(state);\n if (!this.seed.isConnected) {\n return;\n }\n // Adapted from https://www.shadertoy.com/view/MslGD8\n let functionString = `vec2 voronoiRandom(vec2 p){\n p = vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3)));\n return fract(sin(p)*18.5453);\n }\n `;\n if (state.shaderLanguage === 1 /* ShaderLanguage.WGSL */) {\n functionString = state._babylonSLtoWGSL(functionString);\n }\n state._emitFunction(\"voronoiRandom\", functionString, \"// Voronoi random generator\");\n functionString = `void voronoi(vec2 seed, float offset, float density, out float outValue, out float cells){\n vec2 n = floor(seed * density);\n vec2 f = fract(seed * density);\n vec3 m = vec3( 8.0 );\n for( int j=-1; j<=1; j++ ){\n for( int i=-1; i<=1; i++ ){\n vec2 g = vec2( float(i), float(j) );\n vec2 o = voronoiRandom( n + g);\n vec2 r = g - f + (0.5+0.5*sin(offset+6.2831*o));\n float d = dot( r, r );\n if( d<m.x ){\n m = vec3( d, o );\n outValue = m.x;\n cells = m.y;\n }\n }\n\t\t\t}\n }\n `;\n if (state.shaderLanguage === 1 /* ShaderLanguage.WGSL */) {\n functionString = state._babylonSLtoWGSL(functionString);\n } else {\n functionString = state._babylonSLtoGLSL(functionString);\n }\n state._emitFunction(\"voronoi\", functionString, \"// Voronoi\");\n const tempOutput = state._getFreeVariableName(\"tempOutput\");\n const tempCells = state._getFreeVariableName(\"tempCells\");\n const ref = state.shaderLanguage === 1 /* ShaderLanguage.WGSL */ ? \"&\" : \"\";\n state.compilationString += `${state._declareLocalVar(tempOutput, NodeMaterialBlockConnectionPointTypes.Float)} = 0.0;\\n`;\n state.compilationString += `${state._declareLocalVar(tempCells, NodeMaterialBlockConnectionPointTypes.Float)} = 0.0;\\n`;\n state.compilationString += `voronoi(${this.seed.associatedVariableName}, ${this.offset.associatedVariableName}, ${this.density.associatedVariableName}, ${ref}${tempOutput}, ${ref}${tempCells});\\n`;\n if (this.output.hasEndpoints) {\n state.compilationString += state._declareOutput(this.output) + ` = ${tempOutput};\\n`;\n }\n if (this.cells.hasEndpoints) {\n state.compilationString += state._declareOutput(this.cells) + ` = ${tempCells};\\n`;\n }\n return this;\n }\n}\nRegisterClass(\"BABYLON.VoronoiNoiseBlock\", VoronoiNoiseBlock);","map":{"version":3,"names":["NodeMaterialBlock","NodeMaterialBlockConnectionPointTypes","NodeMaterialBlockTargets","RegisterClass","VoronoiNoiseBlock","constructor","name","Neutral","registerInput","Vector2","Float","registerOutput","getClassName","seed","_inputs","offset","density","output","_outputs","cells","_buildBlock","state","isConnected","functionString","shaderLanguage","_babylonSLtoWGSL","_emitFunction","_babylonSLtoGLSL","tempOutput","_getFreeVariableName","tempCells","ref","compilationString","_declareLocalVar","associatedVariableName","hasEndpoints","_declareOutput"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Materials/Node/Blocks/voronoiNoiseBlock.js"],"sourcesContent":["import { NodeMaterialBlock } from \"../nodeMaterialBlock.js\";\nimport { NodeMaterialBlockConnectionPointTypes } from \"../Enums/nodeMaterialBlockConnectionPointTypes.js\";\nimport { NodeMaterialBlockTargets } from \"../Enums/nodeMaterialBlockTargets.js\";\nimport { RegisterClass } from \"../../../Misc/typeStore.js\";\n/**\n * block used to Generate a Voronoi Noise Pattern\n */\nexport class VoronoiNoiseBlock extends NodeMaterialBlock {\n /**\n * Creates a new VoronoiNoiseBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.Neutral);\n this.registerInput(\"seed\", NodeMaterialBlockConnectionPointTypes.Vector2);\n this.registerInput(\"offset\", NodeMaterialBlockConnectionPointTypes.Float);\n this.registerInput(\"density\", NodeMaterialBlockConnectionPointTypes.Float);\n this.registerOutput(\"output\", NodeMaterialBlockConnectionPointTypes.Float);\n this.registerOutput(\"cells\", NodeMaterialBlockConnectionPointTypes.Float);\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"VoronoiNoiseBlock\";\n }\n /**\n * Gets the seed input component\n */\n get seed() {\n return this._inputs[0];\n }\n /**\n * Gets the offset input component\n */\n get offset() {\n return this._inputs[1];\n }\n /**\n * Gets the density input component\n */\n get density() {\n return this._inputs[2];\n }\n /**\n * Gets the output component\n */\n get output() {\n return this._outputs[0];\n }\n /**\n * Gets the output component\n */\n get cells() {\n return this._outputs[1];\n }\n _buildBlock(state) {\n super._buildBlock(state);\n if (!this.seed.isConnected) {\n return;\n }\n // Adapted from https://www.shadertoy.com/view/MslGD8\n let functionString = `vec2 voronoiRandom(vec2 p){\r\n p = vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3)));\r\n return fract(sin(p)*18.5453);\r\n }\r\n `;\n if (state.shaderLanguage === 1 /* ShaderLanguage.WGSL */) {\n functionString = state._babylonSLtoWGSL(functionString);\n }\n state._emitFunction(\"voronoiRandom\", functionString, \"// Voronoi random generator\");\n functionString = `void voronoi(vec2 seed, float offset, float density, out float outValue, out float cells){\r\n vec2 n = floor(seed * density);\r\n vec2 f = fract(seed * density);\r\n vec3 m = vec3( 8.0 );\r\n for( int j=-1; j<=1; j++ ){\r\n for( int i=-1; i<=1; i++ ){\r\n vec2 g = vec2( float(i), float(j) );\r\n vec2 o = voronoiRandom( n + g);\r\n vec2 r = g - f + (0.5+0.5*sin(offset+6.2831*o));\r\n float d = dot( r, r );\r\n if( d<m.x ){\r\n m = vec3( d, o );\r\n outValue = m.x;\r\n cells = m.y;\r\n }\r\n }\r\n\t\t\t}\r\n }\r\n `;\n if (state.shaderLanguage === 1 /* ShaderLanguage.WGSL */) {\n functionString = state._babylonSLtoWGSL(functionString);\n }\n else {\n functionString = state._babylonSLtoGLSL(functionString);\n }\n state._emitFunction(\"voronoi\", functionString, \"// Voronoi\");\n const tempOutput = state._getFreeVariableName(\"tempOutput\");\n const tempCells = state._getFreeVariableName(\"tempCells\");\n const ref = state.shaderLanguage === 1 /* ShaderLanguage.WGSL */ ? \"&\" : \"\";\n state.compilationString += `${state._declareLocalVar(tempOutput, NodeMaterialBlockConnectionPointTypes.Float)} = 0.0;\\n`;\n state.compilationString += `${state._declareLocalVar(tempCells, NodeMaterialBlockConnectionPointTypes.Float)} = 0.0;\\n`;\n state.compilationString += `voronoi(${this.seed.associatedVariableName}, ${this.offset.associatedVariableName}, ${this.density.associatedVariableName}, ${ref}${tempOutput}, ${ref}${tempCells});\\n`;\n if (this.output.hasEndpoints) {\n state.compilationString += state._declareOutput(this.output) + ` = ${tempOutput};\\n`;\n }\n if (this.cells.hasEndpoints) {\n state.compilationString += state._declareOutput(this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