2
0

CameraNode.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.CameraNode = function( scope, camera ) {
  5. THREE.TempNode.call( this, 'v3' );
  6. this.setScope( scope || THREE.CameraNode.POSITION );
  7. this.setCamera( camera );
  8. };
  9. THREE.CameraNode.prototype = Object.create( THREE.TempNode.prototype );
  10. THREE.CameraNode.prototype.constructor = THREE.CameraNode;
  11. THREE.CameraNode.POSITION = 'position';
  12. THREE.CameraNode.DEPTH = 'depth';
  13. THREE.CameraNode.prototype.setCamera = function( camera ) {
  14. this.camera = camera;
  15. this.requestUpdate = camera !== undefined;
  16. };
  17. THREE.CameraNode.prototype.setScope = function( scope ) {
  18. switch ( this.scope ) {
  19. case THREE.CameraNode.DEPTH:
  20. delete this.near;
  21. delete this.far;
  22. break;
  23. }
  24. this.scope = scope;
  25. switch ( scope ) {
  26. case THREE.CameraNode.DEPTH:
  27. this.near = new THREE.FloatNode( camera ? camera.near : 1 );
  28. this.far = new THREE.FloatNode( camera ? camera.far : 1200 );
  29. break;
  30. }
  31. };
  32. THREE.CameraNode.prototype.getType = function( builder ) {
  33. switch ( this.scope ) {
  34. case THREE.CameraNode.DEPTH:
  35. return 'fv1';
  36. }
  37. return this.type;
  38. };
  39. THREE.CameraNode.prototype.isUnique = function( builder ) {
  40. switch ( this.scope ) {
  41. case THREE.CameraNode.DEPTH:
  42. return true;
  43. }
  44. return false;
  45. };
  46. THREE.CameraNode.prototype.isShared = function( builder ) {
  47. switch ( this.scope ) {
  48. case THREE.CameraNode.POSITION:
  49. return false;
  50. }
  51. return true;
  52. };
  53. THREE.CameraNode.prototype.generate = function( builder, output ) {
  54. var material = builder.material;
  55. var result;
  56. switch ( this.scope ) {
  57. case THREE.CameraNode.POSITION:
  58. result = 'cameraPosition';
  59. break;
  60. case THREE.CameraNode.DEPTH:
  61. builder.include( 'depthcolor' );
  62. result = 'depthcolor(' + this.near.build( builder, 'fv1' ) + ',' + this.far.build( builder, 'fv1' ) + ')';
  63. break;
  64. }
  65. return builder.format( result, this.getType( builder ), output );
  66. };
  67. THREE.CameraNode.prototype.updateAnimation = function( delta ) {
  68. switch ( this.scope ) {
  69. case THREE.CameraNode.DEPTH:
  70. this.near.number = camera.near;
  71. this.far.number = camera.far;
  72. break;
  73. }
  74. };