NodeCamera.js 1.8 KB

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