Math1Node.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.nodeType = "Math1";
  36. THREE.Math1Node.prototype.getType = function ( builder ) {
  37. switch ( this.method ) {
  38. case THREE.Math1Node.LENGTH:
  39. return 'fv1';
  40. }
  41. return this.a.getType( builder );
  42. };
  43. THREE.Math1Node.prototype.generate = function ( builder, output ) {
  44. var material = builder.material;
  45. var type = this.getType( builder );
  46. var result = this.a.build( builder, type );
  47. switch ( this.method ) {
  48. case THREE.Math1Node.NEGATE:
  49. result = '( -' + result + ' )';
  50. break;
  51. case THREE.Math1Node.INVERT:
  52. result = '( 1.0 - ' + result + ' )';
  53. break;
  54. default:
  55. result = this.method + '( ' + result + ' )';
  56. break;
  57. }
  58. return builder.format( result, type, output );
  59. };
  60. THREE.Math1Node.prototype.copy = function ( source ) {
  61. THREE.GLNode.prototype.copy.call( this, source );
  62. this.a = source.a;
  63. this.method = source.method;
  64. };
  65. THREE.Math1Node.prototype.toJSON = function ( meta ) {
  66. var data = this.getJSONNode( meta );
  67. if ( ! data ) {
  68. data = this.createJSONNode( meta );
  69. data.a = this.a.toJSON( meta ).uuid;
  70. data.method = this.method;
  71. }
  72. return data;
  73. };