CameraNode.js 1006 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import Object3DNode from './Object3DNode.js';
  2. class CameraNode extends Object3DNode {
  3. constructor( scope = CameraNode.POSITION ) {
  4. super( scope );
  5. }
  6. getNodeType( builder ) {
  7. const scope = this.scope;
  8. if ( scope === CameraNode.PROJECTION_MATRIX ) {
  9. return 'mat4';
  10. }
  11. return super.getNodeType( builder );
  12. }
  13. update( frame ) {
  14. const camera = frame.camera;
  15. const uniformNode = this._uniformNode;
  16. const scope = this.scope;
  17. if ( scope === CameraNode.PROJECTION_MATRIX ) {
  18. uniformNode.value = camera.projectionMatrix;
  19. } else if ( scope === CameraNode.VIEW_MATRIX ) {
  20. uniformNode.value = camera.matrixWorldInverse;
  21. } else {
  22. this.object3d = camera;
  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. CameraNode.PROJECTION_MATRIX = 'projectionMatrix';
  35. export default CameraNode;