MeshPhysicalMaterial.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. * reflectivity: <float>,
  15. * ior: <float>,
  16. *
  17. * sheen: <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. constructor( parameters ) {
  35. super();
  36. this.defines = {
  37. 'STANDARD': '',
  38. 'PHYSICAL': ''
  39. };
  40. this.type = 'MeshPhysicalMaterial';
  41. this.clearcoat = 0.0;
  42. this.clearcoatMap = null;
  43. this.clearcoatRoughness = 0.0;
  44. this.clearcoatRoughnessMap = null;
  45. this.clearcoatNormalScale = new Vector2( 1, 1 );
  46. this.clearcoatNormalMap = null;
  47. this.reflectivity = 0.5; // maps to F0 = 0.04
  48. Object.defineProperty( this, 'ior', {
  49. get: function () {
  50. return ( 1 + 0.4 * this.reflectivity ) / ( 1 - 0.4 * this.reflectivity );
  51. },
  52. set: function ( ior ) {
  53. this.reflectivity = MathUtils.clamp( 2.5 * ( ior - 1 ) / ( ior + 1 ), 0, 1 );
  54. }
  55. } );
  56. this.sheen = null; // null will disable sheen bsdf
  57. this.transmission = 0.0;
  58. this.transmissionMap = null;
  59. this.thickness = 0.01;
  60. this.thicknessMap = null;
  61. this.attenuationDistance = 0.0;
  62. this.attenuationTint = new Color( 1, 1, 1 );
  63. this.specularIntensity = 1.0;
  64. this.specularIntensityMap = null;
  65. this.specularTint = new Color( 1, 1, 1 );
  66. this.specularTintMap = null;
  67. this.setValues( parameters );
  68. }
  69. copy( source ) {
  70. super.copy( source );
  71. this.defines = {
  72. 'STANDARD': '',
  73. 'PHYSICAL': ''
  74. };
  75. this.clearcoat = source.clearcoat;
  76. this.clearcoatMap = source.clearcoatMap;
  77. this.clearcoatRoughness = source.clearcoatRoughness;
  78. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  79. this.clearcoatNormalMap = source.clearcoatNormalMap;
  80. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  81. this.reflectivity = source.reflectivity;
  82. if ( source.sheen ) {
  83. this.sheen = ( this.sheen || new Color() ).copy( source.sheen );
  84. } else {
  85. this.sheen = null;
  86. }
  87. this.transmission = source.transmission;
  88. this.transmissionMap = source.transmissionMap;
  89. this.thickness = source.thickness;
  90. this.thicknessMap = source.thicknessMap;
  91. this.attenuationDistance = source.attenuationDistance;
  92. this.attenuationTint.copy( source.attenuationTint );
  93. this.specularIntensity = source.specularIntensity;
  94. this.specularIntensityMap = source.specularIntensityMap;
  95. this.specularTint.copy( source.specularTint );
  96. this.specularTintMap = source.specularTintMap;
  97. return this;
  98. }
  99. }
  100. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  101. export { MeshPhysicalMaterial };