Math1Node.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.toJSON = function ( meta ) {
  61. var data = this.getJSONNode( meta );
  62. if ( ! data ) {
  63. data = this.createJSONNode( meta );
  64. data.a = this.a.toJSON( meta ).uuid;
  65. data.method = this.method;
  66. }
  67. return data;
  68. };