NodeFunctionCall.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.NodeFunctionCall = function( value ) {
  5. THREE.NodeTemp.call( this );
  6. this.setFunction( value );
  7. };
  8. THREE.NodeFunctionCall.prototype = Object.create( THREE.NodeTemp.prototype );
  9. THREE.NodeFunctionCall.prototype.constructor = THREE.NodeFunctionCall;
  10. THREE.NodeFunctionCall.prototype.setFunction = function(val) {
  11. this.input = [];
  12. this.value = val;
  13. };
  14. THREE.NodeFunctionCall.prototype.getFunction = function() {
  15. return this.value;
  16. };
  17. THREE.NodeFunctionCall.prototype.getType = function( builder ) {
  18. return this.value.getType( builder );
  19. };
  20. THREE.NodeFunctionCall.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. };