PositionNode.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.PositionNode = function( scope ) {
  5. THREE.TempNode.call( this, 'v3' );
  6. this.scope = scope || THREE.PositionNode.LOCAL;
  7. };
  8. THREE.PositionNode.LOCAL = 'local';
  9. THREE.PositionNode.WORLD = 'world';
  10. THREE.PositionNode.VIEW = 'view';
  11. THREE.PositionNode.PROJECTION = 'projection';
  12. THREE.PositionNode.prototype = Object.create( THREE.TempNode.prototype );
  13. THREE.PositionNode.prototype.constructor = THREE.PositionNode;
  14. THREE.PositionNode.prototype.getType = function( builder ) {
  15. switch ( this.scope ) {
  16. case THREE.PositionNode.PROJECTION:
  17. return 'v4';
  18. }
  19. return this.type;
  20. };
  21. THREE.PositionNode.prototype.isShared = function( builder ) {
  22. switch ( this.scope ) {
  23. case THREE.PositionNode.LOCAL:
  24. case THREE.PositionNode.WORLD:
  25. return false;
  26. }
  27. return true;
  28. };
  29. THREE.PositionNode.prototype.generate = function( builder, output ) {
  30. var material = builder.material;
  31. var result;
  32. switch ( this.scope ) {
  33. case THREE.PositionNode.LOCAL:
  34. material.requestAttribs.position = true;
  35. if ( builder.isShader( 'vertex' ) ) result = 'transformed';
  36. else result = 'vPosition';
  37. break;
  38. case THREE.PositionNode.WORLD:
  39. material.requestAttribs.worldPosition = true;
  40. if ( builder.isShader( 'vertex' ) ) result = 'vWPosition';
  41. else result = 'vWPosition';
  42. break;
  43. case THREE.PositionNode.VIEW:
  44. if ( builder.isShader( 'vertex' ) ) result = '-mvPosition.xyz';
  45. else result = 'vViewPosition';
  46. break;
  47. case THREE.PositionNode.PROJECTION:
  48. if ( builder.isShader( 'vertex' ) ) result = '(projectionMatrix * modelViewMatrix * vec4( position, 1.0 ))';
  49. else result = 'vec4( 0.0 )';
  50. break;
  51. }
  52. return builder.format( result, this.getType( builder ), output );
  53. };