FunctionCallNode.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.FunctionCallNode = function( func, inputs ) {
  5. THREE.TempNode.call( this );
  6. this.setFunction( func, inputs );
  7. };
  8. THREE.FunctionCallNode.prototype = Object.create( THREE.TempNode.prototype );
  9. THREE.FunctionCallNode.prototype.constructor = THREE.FunctionCallNode;
  10. THREE.FunctionCallNode.prototype.setFunction = function( func, inputs ) {
  11. this.value = func;
  12. this.inputs = inputs || [];
  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. var code = func.build( builder, output ) + '(';
  25. var params = [];
  26. for ( var i = 0; i < func.inputs.length; i ++ ) {
  27. var inpt = func.inputs[ i ];
  28. var param = this.inputs[ i ] || this.inputs[ inpt.name ];
  29. params.push( param.build( builder, builder.getTypeByFormat( inpt.type ) ) );
  30. }
  31. code += params.join( ',' ) + ')';
  32. return builder.format( code, type, output );
  33. };