MeshPhysicalMaterial.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. /**
  6. * parameters = {
  7. * clearcoat: <float>,
  8. * clearcoatMap: new THREE.Texture( <Image> ),
  9. * clearcoatRoughness: <float>,
  10. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  11. * clearcoatNormalScale: <Vector2>,
  12. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  13. *
  14. * ior: <float>,
  15. * reflectivity: <float>,
  16. *
  17. * sheenTint: <Color>,
  18. *
  19. * transmission: <float>,
  20. * transmissionMap: new THREE.Texture( <Image> ),
  21. *
  22. * thickness: <float>,
  23. * thicknessMap: new THREE.Texture( <Image> ),
  24. * attenuationDistance: <float>,
  25. * attenuationTint: <Color>,
  26. *
  27. * specularIntensity: <float>,
  28. * specularIntensityhMap: new THREE.Texture( <Image> ),
  29. * specularTint: <Color>,
  30. * specularTintMap: new THREE.Texture( <Image> )
  31. * }
  32. */
  33. class MeshPhysicalMaterial extends MeshStandardMaterial {
  34. #clearcoat = 0;
  35. #transmission = 0;
  36. constructor( parameters ) {
  37. super();
  38. this.defines = {
  39. 'STANDARD': '',
  40. 'PHYSICAL': ''
  41. };
  42. this.type = 'MeshPhysicalMaterial';
  43. this.clearcoatMap = null;
  44. this.clearcoatRoughness = 0.0;
  45. this.clearcoatRoughnessMap = null;
  46. this.clearcoatNormalScale = new Vector2( 1, 1 );
  47. this.clearcoatNormalMap = null;
  48. this.ior = 1.5;
  49. Object.defineProperty( this, 'reflectivity', {
  50. get: function () {
  51. return ( MathUtils.clamp( 2.5 * ( this.ior - 1 ) / ( this.ior + 1 ), 0, 1 ) );
  52. },
  53. set: function ( reflectivity ) {
  54. this.ior = ( 1 + 0.4 * reflectivity ) / ( 1 - 0.4 * reflectivity );
  55. }
  56. } );
  57. this.sheenTint = new Color( 0x000000 );
  58. this.transmission = 0.0;
  59. this.transmissionMap = null;
  60. this.thickness = 0.01;
  61. this.thicknessMap = null;
  62. this.attenuationDistance = 0.0;
  63. this.attenuationTint = new Color( 1, 1, 1 );
  64. this.specularIntensity = 1.0;
  65. this.specularIntensityMap = null;
  66. this.specularTint = new Color( 1, 1, 1 );
  67. this.specularTintMap = null;
  68. this.setValues( parameters );
  69. }
  70. get clearcoat() {
  71. return this.#clearcoat;
  72. }
  73. set clearcoat( value ) {
  74. if ( this.#clearcoat > 0 !== value > 0 ) {
  75. this.version ++;
  76. }
  77. this.#clearcoat = value;
  78. }
  79. get transmission() {
  80. return this.#transmission;
  81. }
  82. set transmission( value ) {
  83. if ( this.#transmission > 0 !== value > 0 ) {
  84. this.version ++;
  85. }
  86. this.#transmission = value;
  87. }
  88. copy( source ) {
  89. super.copy( source );
  90. this.defines = {
  91. 'STANDARD': '',
  92. 'PHYSICAL': ''
  93. };
  94. this.clearcoat = source.clearcoat;
  95. this.clearcoatMap = source.clearcoatMap;
  96. this.clearcoatRoughness = source.clearcoatRoughness;
  97. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  98. this.clearcoatNormalMap = source.clearcoatNormalMap;
  99. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  100. this.ior = source.ior;
  101. this.sheenTint.copy( source.sheenTint );
  102. this.transmission = source.transmission;
  103. this.transmissionMap = source.transmissionMap;
  104. this.thickness = source.thickness;
  105. this.thicknessMap = source.thicknessMap;
  106. this.attenuationDistance = source.attenuationDistance;
  107. this.attenuationTint.copy( source.attenuationTint );
  108. this.specularIntensity = source.specularIntensity;
  109. this.specularIntensityMap = source.specularIntensityMap;
  110. this.specularTint.copy( source.specularTint );
  111. this.specularTintMap = source.specularTintMap;
  112. return this;
  113. }
  114. }
  115. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  116. export { MeshPhysicalMaterial };