CameraNode.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import Object3DNode from './Object3DNode.js';
  2. import Matrix4Node from '../inputs/Matrix4Node.js';
  3. class CameraNode extends Object3DNode {
  4. static PROJECTION_MATRIX = 'projectionMatrix';
  5. constructor( scope = CameraNode.POSITION ) {
  6. super( scope );
  7. this._inputNode = null;
  8. }
  9. getNodeType( builder ) {
  10. const scope = this.scope;
  11. if ( scope === CameraNode.PROJECTION_MATRIX ) {
  12. return 'mat4';
  13. }
  14. return super.getNodeType( builder );
  15. }
  16. update( frame ) {
  17. const camera = frame.camera;
  18. const inputNode = this._inputNode;
  19. const scope = this.scope;
  20. if ( scope === CameraNode.PROJECTION_MATRIX ) {
  21. inputNode.value = camera.projectionMatrix;
  22. } else if ( scope === CameraNode.VIEW_MATRIX ) {
  23. inputNode.value = camera.matrixWorldInverse;
  24. } else {
  25. super.update( frame );
  26. }
  27. }
  28. generate( builder ) {
  29. const scope = this.scope;
  30. if ( scope === CameraNode.PROJECTION_MATRIX ) {
  31. this._inputNode = new Matrix4Node( null );
  32. }
  33. return super.generate( builder );
  34. }
  35. }
  36. export default CameraNode;