MaxMipLevelNode.js 722 B

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