MaxMIPLevelNode.js 1.0 KB

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