Math1Node.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.Math1Node = function( a, method ) {
  5. THREE.TempNode.call( this );
  6. this.a = a;
  7. this.method = method || THREE.Math1Node.SIN;
  8. };
  9. THREE.Math1Node.prototype = Object.create( THREE.TempNode.prototype );
  10. THREE.Math1Node.prototype.constructor = THREE.Math1Node;
  11. THREE.Math1Node.RAD = 'radians';
  12. THREE.Math1Node.DEG = 'degrees';
  13. THREE.Math1Node.EXP = 'exp';
  14. THREE.Math1Node.EXP2 = 'exp2';
  15. THREE.Math1Node.LOG = 'log';
  16. THREE.Math1Node.LOG2 = 'log2';
  17. THREE.Math1Node.INVERSE_SQRT = 'inversesqrt';
  18. THREE.Math1Node.FLOOR = 'floor';
  19. THREE.Math1Node.CEIL = 'ceil';
  20. THREE.Math1Node.NORMALIZE = 'normalize';
  21. THREE.Math1Node.FRACT = 'fract';
  22. THREE.Math1Node.SAT = 'saturate';
  23. THREE.Math1Node.SIN = 'sin';
  24. THREE.Math1Node.COS = 'cos';
  25. THREE.Math1Node.TAN = 'tan';
  26. THREE.Math1Node.ASIN = 'asin';
  27. THREE.Math1Node.ACOS = 'acos';
  28. THREE.Math1Node.ARCTAN = 'atan';
  29. THREE.Math1Node.ABS = 'abc';
  30. THREE.Math1Node.SIGN = 'sign';
  31. THREE.Math1Node.LENGTH = 'length';
  32. THREE.Math1Node.NEGATE = 'negate';
  33. THREE.Math1Node.INVERT = 'invert';
  34. THREE.Math1Node.prototype.getType = function( builder ) {
  35. switch ( this.method ) {
  36. case THREE.Math1Node.DISTANCE:
  37. return 'fv1';
  38. }
  39. return this.a.getType( builder );
  40. };
  41. THREE.Math1Node.prototype.generate = function( builder, output ) {
  42. var material = builder.material;
  43. var type = this.getType( builder );
  44. var result = this.a.build( builder, type );
  45. switch ( this.method ) {
  46. case THREE.Math1Node.NEGATE:
  47. result = '(-' + result + ')';
  48. break;
  49. case THREE.Math1Node.INVERT:
  50. result = '(1.0-' + result + ')';
  51. break;
  52. default:
  53. result = this.method + '(' + result + ')';
  54. break;
  55. }
  56. return builder.format( result, type, output );
  57. };