MeshStandardMaterial.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import { TangentSpaceNormalMap } from '../constants.js';
  2. import { Material } from './Material.js';
  3. import { Vector2 } from '../math/Vector2.js';
  4. import { Color } from '../math/Color.js';
  5. /**
  6. * @author WestLangley / http://github.com/WestLangley
  7. *
  8. * parameters = {
  9. * color: <hex>,
  10. * roughness: <float>,
  11. * metalness: <float>,
  12. * opacity: <float>,
  13. *
  14. * map: new THREE.Texture( <Image> ),
  15. *
  16. * lightMap: new THREE.Texture( <Image> ),
  17. * lightMapIntensity: <float>
  18. *
  19. * aoMap: new THREE.Texture( <Image> ),
  20. * aoMapIntensity: <float>
  21. *
  22. * emissive: <hex>,
  23. * emissiveIntensity: <float>
  24. * emissiveMap: new THREE.Texture( <Image> ),
  25. *
  26. * bumpMap: new THREE.Texture( <Image> ),
  27. * bumpScale: <float>,
  28. *
  29. * normalMap: new THREE.Texture( <Image> ),
  30. * normalMapType: THREE.TangentSpaceNormalMap,
  31. * normalScale: <Vector2>,
  32. *
  33. * displacementMap: new THREE.Texture( <Image> ),
  34. * displacementScale: <float>,
  35. * displacementBias: <float>,
  36. *
  37. * roughnessMap: new THREE.Texture( <Image> ),
  38. *
  39. * metalnessMap: new THREE.Texture( <Image> ),
  40. *
  41. * alphaMap: new THREE.Texture( <Image> ),
  42. *
  43. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  44. * envMapIntensity: <float>
  45. *
  46. * refractionRatio: <float>,
  47. *
  48. * wireframe: <boolean>,
  49. * wireframeLinewidth: <float>,
  50. *
  51. * skinning: <bool>,
  52. * morphTargets: <bool>,
  53. * morphNormals: <bool>
  54. * }
  55. */
  56. function MeshStandardMaterial( parameters ) {
  57. Material.call( this );
  58. this.defines = { 'STANDARD': '' };
  59. this.type = 'MeshStandardMaterial';
  60. this.color = new Color( 0xffffff ); // diffuse
  61. this.roughness = 0.5;
  62. this.metalness = 0.5;
  63. this.map = null;
  64. this.lightMap = null;
  65. this.lightMapIntensity = 1.0;
  66. this.aoMap = null;
  67. this.aoMapIntensity = 1.0;
  68. this.emissive = new Color( 0x000000 );
  69. this.emissiveIntensity = 1.0;
  70. this.emissiveMap = null;
  71. this.bumpMap = null;
  72. this.bumpScale = 1;
  73. this.normalMap = null;
  74. this.normalMapType = TangentSpaceNormalMap;
  75. this.normalScale = new Vector2( 1, 1 );
  76. this.displacementMap = null;
  77. this.displacementScale = 1;
  78. this.displacementBias = 0;
  79. this.roughnessMap = null;
  80. this.metalnessMap = null;
  81. this.alphaMap = null;
  82. this.envMap = null;
  83. this.envMapIntensity = 1.0;
  84. this.refractionRatio = 0.98;
  85. this.wireframe = false;
  86. this.wireframeLinewidth = 1;
  87. this.wireframeLinecap = 'round';
  88. this.wireframeLinejoin = 'round';
  89. this.skinning = false;
  90. this.morphTargets = false;
  91. this.morphNormals = false;
  92. this.setValues( parameters );
  93. }
  94. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  95. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  96. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  97. MeshStandardMaterial.prototype.copy = function ( source ) {
  98. Material.prototype.copy.call( this, source );
  99. this.defines = { 'STANDARD': '' };
  100. this.color.copy( source.color );
  101. this.roughness = source.roughness;
  102. this.metalness = source.metalness;
  103. this.map = source.map;
  104. this.lightMap = source.lightMap;
  105. this.lightMapIntensity = source.lightMapIntensity;
  106. this.aoMap = source.aoMap;
  107. this.aoMapIntensity = source.aoMapIntensity;
  108. this.emissive.copy( source.emissive );
  109. this.emissiveMap = source.emissiveMap;
  110. this.emissiveIntensity = source.emissiveIntensity;
  111. this.bumpMap = source.bumpMap;
  112. this.bumpScale = source.bumpScale;
  113. this.normalMap = source.normalMap;
  114. this.normalMapType = source.normalMapType;
  115. this.normalScale.copy( source.normalScale );
  116. this.displacementMap = source.displacementMap;
  117. this.displacementScale = source.displacementScale;
  118. this.displacementBias = source.displacementBias;
  119. this.roughnessMap = source.roughnessMap;
  120. this.metalnessMap = source.metalnessMap;
  121. this.alphaMap = source.alphaMap;
  122. this.envMap = source.envMap;
  123. this.envMapIntensity = source.envMapIntensity;
  124. this.refractionRatio = source.refractionRatio;
  125. this.wireframe = source.wireframe;
  126. this.wireframeLinewidth = source.wireframeLinewidth;
  127. this.wireframeLinecap = source.wireframeLinecap;
  128. this.wireframeLinejoin = source.wireframeLinejoin;
  129. this.skinning = source.skinning;
  130. this.morphTargets = source.morphTargets;
  131. this.morphNormals = source.morphNormals;
  132. return this;
  133. };
  134. export { MeshStandardMaterial };