FunctionCallNode.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.nodeType = "FunctionCall";
  11. THREE.FunctionCallNode.prototype.setFunction = function ( func, inputs ) {
  12. this.value = func;
  13. this.inputs = inputs || [];
  14. };
  15. THREE.FunctionCallNode.prototype.getFunction = function () {
  16. return this.value;
  17. };
  18. THREE.FunctionCallNode.prototype.getType = function ( builder ) {
  19. return this.value.getType( builder );
  20. };
  21. THREE.FunctionCallNode.prototype.generate = function ( builder, output ) {
  22. var material = builder.material;
  23. var type = this.getType( builder );
  24. var func = this.value;
  25. var code = func.build( builder, output ) + '(';
  26. var params = [];
  27. for ( var i = 0; i < func.inputs.length; i ++ ) {
  28. var inpt = func.inputs[ i ];
  29. var param = this.inputs[ i ] || this.inputs[ inpt.name ];
  30. params.push( param.build( builder, builder.getTypeByFormat( inpt.type ) ) );
  31. }
  32. code += params.join( ',' ) + ')';
  33. return builder.format( code, type, output );
  34. };
  35. THREE.FunctionCallNode.prototype.toJSON = function ( meta ) {
  36. var data = this.getJSONNode( meta );
  37. if ( ! data ) {
  38. var func = this.value;
  39. data = this.createJSONNode( meta );
  40. data.value = this.value.toJSON( meta ).uuid;
  41. if ( func.inputs.length ) {
  42. data.inputs = {};
  43. for ( var i = 0; i < func.inputs.length; i ++ ) {
  44. var inpt = func.inputs[ i ];
  45. var node = this.inputs[ i ] || this.inputs[ inpt.name ];
  46. data.inputs[ inpt.name ] = node.toJSON( meta ).uuid;
  47. }
  48. }
  49. }
  50. return data;
  51. };