MaxMipLevelNode.js 606 B

123456789101112131415161718192021222324252627282930313233
  1. import UniformNode from '../core/UniformNode.js';
  2. import { NodeUpdateType } from '../core/constants.js';
  3. class MaxMipLevelNode extends UniformNode {
  4. constructor( texture ) {
  5. super( 0 );
  6. this.texture = texture;
  7. this.updateType = NodeUpdateType.Frame;
  8. }
  9. update() {
  10. const images = this.texture.images;
  11. const image = ( images && images.length > 0 ) ? ( images[ 0 ]?.image || images[ 0 ] ) : this.texture.image;
  12. if ( image?.width !== undefined ) {
  13. const { width, height } = image;
  14. this.value = Math.log2( Math.max( width, height ) );
  15. }
  16. }
  17. }
  18. export default MaxMipLevelNode;