CameraNode.js 2.0 KB

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