TextureNode.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.TextureNode = function( value, coord, bias, project ) {
  5. THREE.InputNode.call( this, 'v4' );
  6. this.value = value;
  7. this.coord = coord || new THREE.UVNode();
  8. this.bias = bias;
  9. this.project = project !== undefined ? project : false;
  10. };
  11. THREE.TextureNode.prototype = Object.create( THREE.InputNode.prototype );
  12. THREE.TextureNode.prototype.constructor = THREE.TextureNode;
  13. THREE.TextureNode.prototype.getTexture = function( builder, output ) {
  14. return THREE.InputNode.prototype.generate.call( this, builder, output, this.value.uuid, 't' );
  15. };
  16. THREE.TextureNode.prototype.generate = function( builder, output ) {
  17. var tex = this.getTexture( builder, output );
  18. var coord = this.coord.build( builder, this.project ? 'v4' : 'v2' );
  19. var bias = this.bias ? this.bias.build( builder, 'fv1' ) : undefined;
  20. if ( bias == undefined && builder.requires.bias ) {
  21. bias = builder.requires.bias.build( builder, 'fv1' );
  22. }
  23. var method, code;
  24. if ( this.project ) method = 'texture2DProj';
  25. else method = bias ? 'tex2DBias' : 'tex2D';
  26. if ( bias ) code = method + '(' + tex + ',' + coord + ',' + bias + ')';
  27. else code = method + '(' + tex + ',' + coord + ')';
  28. return builder.format( code, this.type, output );
  29. };