NodeConst.js 1.1 KB

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