MaxMIPLevelNode.js 998 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { FloatNode } from '../inputs/FloatNode.js';
  2. function MaxMIPLevelNode( texture ) {
  3. FloatNode.call( this );
  4. this.texture = texture;
  5. this.maxMIPLevel = 0;
  6. }
  7. MaxMIPLevelNode.prototype = Object.create( FloatNode.prototype );
  8. MaxMIPLevelNode.prototype.constructor = MaxMIPLevelNode;
  9. MaxMIPLevelNode.prototype.nodeType = 'MaxMIPLevel';
  10. Object.defineProperties( MaxMIPLevelNode.prototype, {
  11. value: {
  12. get: function () {
  13. if ( this.maxMIPLevel === 0 ) {
  14. var image = this.texture.value.image;
  15. if ( Array.isArray( image ) ) image = image[ 0 ];
  16. this.maxMIPLevel = image !== undefined ? Math.log( Math.max( image.width, image.height ) ) * Math.LOG2E : 0;
  17. }
  18. return this.maxMIPLevel;
  19. },
  20. set: function () { }
  21. }
  22. } );
  23. MaxMIPLevelNode.prototype.toJSON = function ( meta ) {
  24. var data = this.getJSONNode( meta );
  25. if ( ! data ) {
  26. data = this.createJSONNode( meta );
  27. data.texture = this.texture.uuid;
  28. }
  29. return data;
  30. };
  31. export { MaxMIPLevelNode };