CameraNode.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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;