FunctionCallNode.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.FunctionCallNode = function( value ) {
  5. THREE.TempNode.call( this );
  6. this.setFunction( value );
  7. };
  8. THREE.FunctionCallNode.prototype = Object.create( THREE.TempNode.prototype );
  9. THREE.FunctionCallNode.prototype.constructor = THREE.FunctionCallNode;
  10. THREE.FunctionCallNode.prototype.setFunction = function( val ) {
  11. this.input = [];
  12. this.value = val;
  13. };
  14. THREE.FunctionCallNode.prototype.getFunction = function() {
  15. return this.value;
  16. };
  17. THREE.FunctionCallNode.prototype.getType = function( builder ) {
  18. return this.value.getType( builder );
  19. };
  20. THREE.FunctionCallNode.prototype.generate = function( builder, output ) {
  21. var material = builder.material;
  22. var type = this.getType( builder );
  23. var func = this.value;
  24. builder.include( func );
  25. var code = func.name + '(';
  26. var params = [];
  27. for ( var i = 0; i < func.input.length; i ++ ) {
  28. var inpt = func.input[ i ];
  29. var param = this.input[ i ] || this.input[ inpt.name ];
  30. params.push( param.build( builder, builder.getType( inpt.type ) ) );
  31. }
  32. code += params.join( ',' ) + ')';
  33. return builder.format( code, type, output );
  34. };