2
0

ConstNode.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.ConstNode = function( name, useDefine ) {
  5. THREE.TempNode.call( this );
  6. this.parse( name || THREE.ConstNode.PI, useDefine );
  7. };
  8. THREE.ConstNode.prototype = Object.create( THREE.TempNode.prototype );
  9. THREE.ConstNode.prototype.constructor = THREE.ConstNode;
  10. THREE.ConstNode.PI = 'PI';
  11. THREE.ConstNode.PI2 = 'PI2';
  12. THREE.ConstNode.RECIPROCAL_PI = 'RECIPROCAL_PI';
  13. THREE.ConstNode.RECIPROCAL_PI2 = 'RECIPROCAL_PI2';
  14. THREE.ConstNode.LOG2 = 'LOG2';
  15. THREE.ConstNode.EPSILON = 'EPSILON';
  16. THREE.ConstNode.prototype.parse = function( src, useDefine ) {
  17. var name, type;
  18. var rDeclaration = /^([a-z_0-9]+)\s([a-z_0-9]+)\s?\=(.*?)\;/i;
  19. var match = src.match( rDeclaration );
  20. if ( match && match.length > 1 ) {
  21. type = match[ 1 ];
  22. name = match[ 2 ];
  23. if ( useDefine ) {
  24. this.src = '#define ' + name + ' ' + match[ 3 ];
  25. }
  26. else {
  27. this.src = 'const ' + type + ' ' + name + ' = ' + match[ 3 ] + ';';
  28. }
  29. }
  30. else {
  31. name = src;
  32. type = 'fv1';
  33. }
  34. this.name = name;
  35. this.type = type;
  36. };
  37. THREE.ConstNode.prototype.generate = function( builder, output ) {
  38. return builder.format( this.name, this.getType( builder ), output );
  39. };