MeshPhysicalMaterial.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import { Vector2 } from '../math/Vector2.js';
  2. import { MeshStandardMaterial } from './MeshStandardMaterial.js';
  3. import { Color } from '../math/Color.js';
  4. import * as MathUtils from '../math/MathUtils.js';
  5. class MeshPhysicalMaterial extends MeshStandardMaterial {
  6. constructor( parameters ) {
  7. super();
  8. this.defines = {
  9. 'STANDARD': '',
  10. 'PHYSICAL': ''
  11. };
  12. this.type = 'MeshPhysicalMaterial';
  13. this.clearcoatMap = null;
  14. this.clearcoatRoughness = 0.0;
  15. this.clearcoatRoughnessMap = null;
  16. this.clearcoatNormalScale = new Vector2( 1, 1 );
  17. this.clearcoatNormalMap = null;
  18. this.ior = 1.5;
  19. Object.defineProperty( this, 'reflectivity', {
  20. get: function () {
  21. return ( MathUtils.clamp( 2.5 * ( this.ior - 1 ) / ( this.ior + 1 ), 0, 1 ) );
  22. },
  23. set: function ( reflectivity ) {
  24. this.ior = ( 1 + 0.4 * reflectivity ) / ( 1 - 0.4 * reflectivity );
  25. }
  26. } );
  27. this.sheenColor = new Color( 0x000000 );
  28. this.sheenColorMap = null;
  29. this.sheenRoughness = 1.0;
  30. this.sheenRoughnessMap = null;
  31. this.transmissionMap = null;
  32. this.thickness = 0;
  33. this.thicknessMap = null;
  34. this.attenuationDistance = 0.0;
  35. this.attenuationColor = new Color( 1, 1, 1 );
  36. this.specularIntensity = 1.0;
  37. this.specularIntensityMap = null;
  38. this.specularColor = new Color( 1, 1, 1 );
  39. this.specularColorMap = null;
  40. this._sheen = 0.0;
  41. this._clearcoat = 0;
  42. this._transmission = 0;
  43. this.setValues( parameters );
  44. }
  45. get sheen() {
  46. return this._sheen;
  47. }
  48. set sheen( value ) {
  49. if ( this._sheen > 0 !== value > 0 ) {
  50. this.version ++;
  51. }
  52. this._sheen = value;
  53. }
  54. get clearcoat() {
  55. return this._clearcoat;
  56. }
  57. set clearcoat( value ) {
  58. if ( this._clearcoat > 0 !== value > 0 ) {
  59. this.version ++;
  60. }
  61. this._clearcoat = value;
  62. }
  63. get transmission() {
  64. return this._transmission;
  65. }
  66. set transmission( value ) {
  67. if ( this._transmission > 0 !== value > 0 ) {
  68. this.version ++;
  69. }
  70. this._transmission = value;
  71. }
  72. copy( source ) {
  73. super.copy( source );
  74. this.defines = {
  75. 'STANDARD': '',
  76. 'PHYSICAL': ''
  77. };
  78. this.clearcoat = source.clearcoat;
  79. this.clearcoatMap = source.clearcoatMap;
  80. this.clearcoatRoughness = source.clearcoatRoughness;
  81. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  82. this.clearcoatNormalMap = source.clearcoatNormalMap;
  83. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  84. this.ior = source.ior;
  85. this.sheen = source.sheen;
  86. this.sheenColor.copy( source.sheenColor );
  87. this.sheenColorMap = source.sheenColorMap;
  88. this.sheenRoughness = source.sheenRoughness;
  89. this.sheenRoughnessMap = source.sheenRoughnessMap;
  90. this.transmission = source.transmission;
  91. this.transmissionMap = source.transmissionMap;
  92. this.thickness = source.thickness;
  93. this.thicknessMap = source.thicknessMap;
  94. this.attenuationDistance = source.attenuationDistance;
  95. this.attenuationColor.copy( source.attenuationColor );
  96. this.specularIntensity = source.specularIntensity;
  97. this.specularIntensityMap = source.specularIntensityMap;
  98. this.specularColor.copy( source.specularColor );
  99. this.specularColorMap = source.specularColorMap;
  100. return this;
  101. }
  102. }
  103. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  104. export { MeshPhysicalMaterial };