CameraNode.js 975 B

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