NormalNode.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.isShared = function( builder ) {
  14. switch ( this.scope ) {
  15. case THREE.NormalNode.WORLD:
  16. return true;
  17. }
  18. return false;
  19. };
  20. THREE.NormalNode.prototype.generate = function( builder, output ) {
  21. var material = builder.material;
  22. var result;
  23. switch ( this.scope ) {
  24. case THREE.NormalNode.LOCAL:
  25. material.requestAttribs.normal = true;
  26. if ( builder.isShader( 'vertex' ) ) result = 'normal';
  27. else result = 'vObjectNormal';
  28. break;
  29. case THREE.NormalNode.WORLD:
  30. material.requestAttribs.worldNormal = true;
  31. if ( builder.isShader( 'vertex' ) ) result = '( modelMatrix * vec4( objectNormal, 0.0 ) ).xyz';
  32. else result = 'vWNormal';
  33. break;
  34. case THREE.NormalNode.VIEW:
  35. result = 'vNormal';
  36. break;
  37. }
  38. return builder.format( result, this.getType( builder ), output );
  39. };