NormalNode.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.NormalNode = function ( scope ) {
  5. THREE.TempNode.call( this, 'v3' );
  6. this.scope = scope || THREE.NormalNode.LOCAL;
  7. };
  8. THREE.NormalNode.LOCAL = 'local';
  9. THREE.NormalNode.WORLD = 'world';
  10. THREE.NormalNode.VIEW = 'view';
  11. THREE.NormalNode.prototype = Object.create( THREE.TempNode.prototype );
  12. THREE.NormalNode.prototype.constructor = THREE.NormalNode;
  13. THREE.NormalNode.prototype.nodeType = "Normal";
  14. THREE.NormalNode.prototype.isShared = function ( builder ) {
  15. switch ( this.scope ) {
  16. case THREE.NormalNode.WORLD:
  17. return true;
  18. }
  19. return false;
  20. };
  21. THREE.NormalNode.prototype.generate = function ( builder, output ) {
  22. var material = builder.material;
  23. var result;
  24. switch ( this.scope ) {
  25. case THREE.NormalNode.LOCAL:
  26. material.requires.normal = true;
  27. if ( builder.isShader( 'vertex' ) ) result = 'normal';
  28. else result = 'vObjectNormal';
  29. break;
  30. case THREE.NormalNode.WORLD:
  31. material.requires.worldNormal = true;
  32. if ( builder.isShader( 'vertex' ) ) result = '( modelMatrix * vec4( objectNormal, 0.0 ) ).xyz';
  33. else result = 'vWNormal';
  34. break;
  35. case THREE.NormalNode.VIEW:
  36. result = 'vNormal';
  37. break;
  38. }
  39. return builder.format( result, this.getType( builder ), output );
  40. };
  41. THREE.NormalNode.prototype.copy = function ( source ) {
  42. THREE.GLNode.prototype.copy.call( this, source );
  43. this.scope = source.scope;
  44. };
  45. THREE.NormalNode.prototype.toJSON = function ( meta ) {
  46. var data = this.getJSONNode( meta );
  47. if ( ! data ) {
  48. data = this.createJSONNode( meta );
  49. data.scope = this.scope;
  50. }
  51. return data;
  52. };
粤ICP备19079148号