CameraNode.js 1003 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. this.object3d = camera;
  24. super.update( frame );
  25. }
  26. }
  27. generate( builder ) {
  28. const scope = this.scope;
  29. if ( scope === CameraNode.PROJECTION_MATRIX ) {
  30. this._uniformNode.nodeType = 'mat4';
  31. }
  32. return super.generate( builder );
  33. }
  34. }
  35. export default CameraNode;