Math1Node.js 1.7 KB

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