Spaces:
Running
Running
File size: 1,444 Bytes
6cd9596 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
/**
* @author sunag / http://www.sunag.com.br/
*/
import { TempNode } from '../core/TempNode.js';
import { FunctionNode } from '../core/FunctionNode.js';
import { UVNode } from '../accessors/UVNode.js';
function CheckerNode( uv ) {
TempNode.call( this, 'f' );
this.uv = uv || new UVNode();
}
CheckerNode.prototype = Object.create( TempNode.prototype );
CheckerNode.prototype.constructor = CheckerNode;
CheckerNode.prototype.nodeType = "Noise";
CheckerNode.Nodes = ( function () {
// https://github.com/mattdesl/glsl-checker/blob/master/index.glsl
var checker = new FunctionNode( [
"float checker( vec2 uv ) {",
" float cx = floor( uv.x );",
" float cy = floor( uv.y ); ",
" float result = mod( cx + cy, 2.0 );",
" return sign( result );",
"}"
].join( "\n" ) );
return {
checker: checker
};
} )();
CheckerNode.prototype.generate = function ( builder, output ) {
var snoise = builder.include( CheckerNode.Nodes.checker );
return builder.format( snoise + '( ' + this.uv.build( builder, 'v2' ) + ' )', this.getType( builder ), output );
};
CheckerNode.prototype.copy = function ( source ) {
TempNode.prototype.copy.call( this, source );
this.uv = source.uv;
};
CheckerNode.prototype.toJSON = function ( meta ) {
var data = this.getJSONNode( meta );
if ( ! data ) {
data = this.createJSONNode( meta );
data.uv = this.uv.toJSON( meta ).uuid;
}
return data;
};
export { CheckerNode };
|