MeshPhysicalMaterial.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. * sheen: <float>,
  18. * sheenColor: <Color>,
  19. * sheenColorMap: new THREE.Texture( <Image> ),
  20. * sheenRoughness: <float>,
  21. * sheenRoughnessMap: new THREE.Texture( <Image> ),
  22. *
  23. * transmission: <float>,
  24. * transmissionMap: new THREE.Texture( <Image> ),
  25. *
  26. * thickness: <float>,
  27. * thicknessMap: new THREE.Texture( <Image> ),
  28. * attenuationDistance: <float>,
  29. * attenuationColor: <Color>,
  30. *
  31. * specularIntensity: <float>,
  32. * specularIntensityMap: new THREE.Texture( <Image> ),
  33. * specularColor: <Color>,
  34. * specularColorMap: new THREE.Texture( <Image> )
  35. * }
  36. */
  37. class MeshPhysicalMaterial extends MeshStandardMaterial {
  38. constructor( parameters ) {
  39. super();
  40. this.defines = {
  41. 'STANDARD': '',
  42. 'PHYSICAL': ''
  43. };
  44. this.type = 'MeshPhysicalMaterial';
  45. this.clearcoatMap = null;
  46. this.clearcoatRoughness = 0.0;
  47. this.clearcoatRoughnessMap = null;
  48. this.clearcoatNormalScale = new Vector2( 1, 1 );
  49. this.clearcoatNormalMap = null;
  50. this.ior = 1.5;
  51. Object.defineProperty( this, 'reflectivity', {
  52. get: function () {
  53. return ( MathUtils.clamp( 2.5 * ( this.ior - 1 ) / ( this.ior + 1 ), 0, 1 ) );
  54. },
  55. set: function ( reflectivity ) {
  56. this.ior = ( 1 + 0.4 * reflectivity ) / ( 1 - 0.4 * reflectivity );
  57. }
  58. } );
  59. this.sheenColor = new Color( 0x000000 );
  60. this.sheenColorMap = null;
  61. this.sheenRoughness = 1.0;
  62. this.sheenRoughnessMap = null;
  63. this.transmissionMap = null;
  64. this.thickness = 0;
  65. this.thicknessMap = null;
  66. this.attenuationDistance = 0.0;
  67. this.attenuationColor = new Color( 1, 1, 1 );
  68. this.specularIntensity = 1.0;
  69. this.specularIntensityMap = null;
  70. this.specularColor = new Color( 1, 1, 1 );
  71. this.specularColorMap = null;
  72. this._sheen = 0.0;
  73. this._clearcoat = 0;
  74. this._transmission = 0;
  75. this.setValues( parameters );
  76. }
  77. get sheen() {
  78. return this._sheen;
  79. }
  80. set sheen( value ) {
  81. if ( this._sheen > 0 !== value > 0 ) {
  82. this.version ++;
  83. }
  84. this._sheen = value;
  85. }
  86. get clearcoat() {
  87. return this._clearcoat;
  88. }
  89. set clearcoat( value ) {
  90. if ( this._clearcoat > 0 !== value > 0 ) {
  91. this.version ++;
  92. }
  93. this._clearcoat = value;
  94. }
  95. get transmission() {
  96. return this._transmission;
  97. }
  98. set transmission( value ) {
  99. if ( this._transmission > 0 !== value > 0 ) {
  100. this.version ++;
  101. }
  102. this._transmission = value;
  103. }
  104. copy( source ) {
  105. super.copy( source );
  106. this.defines = {
  107. 'STANDARD': '',
  108. 'PHYSICAL': ''
  109. };
  110. this.clearcoat = source.clearcoat;
  111. this.clearcoatMap = source.clearcoatMap;
  112. this.clearcoatRoughness = source.clearcoatRoughness;
  113. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  114. this.clearcoatNormalMap = source.clearcoatNormalMap;
  115. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  116. this.ior = source.ior;
  117. this.sheen = source.sheen;
  118. this.sheenColor.copy( source.sheenColor );
  119. this.sheenColorMap = source.sheenColorMap;
  120. this.sheenRoughness = source.sheenRoughness;
  121. this.sheenRoughnessMap = source.sheenRoughnessMap;
  122. this.transmission = source.transmission;
  123. this.transmissionMap = source.transmissionMap;
  124. this.thickness = source.thickness;
  125. this.thicknessMap = source.thicknessMap;
  126. this.attenuationDistance = source.attenuationDistance;
  127. this.attenuationColor.copy( source.attenuationColor );
  128. this.specularIntensity = source.specularIntensity;
  129. this.specularIntensityMap = source.specularIntensityMap;
  130. this.specularColor.copy( source.specularColor );
  131. this.specularColorMap = source.specularColorMap;
  132. return this;
  133. }
  134. }
  135. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  136. export { MeshPhysicalMaterial };
粤ICP备19079148号