MeshPhongMaterial.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import { MultiplyOperation, 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. * parameters = {
  7. * color: <hex>,
  8. * specular: <hex>,
  9. * shininess: <float>,
  10. * opacity: <float>,
  11. *
  12. * map: new THREE.Texture( <Image> ),
  13. *
  14. * lightMap: new THREE.Texture( <Image> ),
  15. * lightMapIntensity: <float>
  16. *
  17. * aoMap: new THREE.Texture( <Image> ),
  18. * aoMapIntensity: <float>
  19. *
  20. * emissive: <hex>,
  21. * emissiveIntensity: <float>
  22. * emissiveMap: new THREE.Texture( <Image> ),
  23. *
  24. * bumpMap: new THREE.Texture( <Image> ),
  25. * bumpScale: <float>,
  26. *
  27. * normalMap: new THREE.Texture( <Image> ),
  28. * normalMapType: THREE.TangentSpaceNormalMap,
  29. * normalScale: <Vector2>,
  30. *
  31. * displacementMap: new THREE.Texture( <Image> ),
  32. * displacementScale: <float>,
  33. * displacementBias: <float>,
  34. *
  35. * specularMap: new THREE.Texture( <Image> ),
  36. *
  37. * alphaMap: new THREE.Texture( <Image> ),
  38. *
  39. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  40. * combine: THREE.MultiplyOperation,
  41. * reflectivity: <float>,
  42. * refractionRatio: <float>,
  43. *
  44. * wireframe: <boolean>,
  45. * wireframeLinewidth: <float>,
  46. *
  47. * flatShading: <bool>
  48. * }
  49. */
  50. class MeshPhongMaterial extends Material {
  51. constructor( parameters ) {
  52. super();
  53. this.type = 'MeshPhongMaterial';
  54. this.color = new Color( 0xffffff ); // diffuse
  55. this.specular = new Color( 0x111111 );
  56. this.shininess = 30;
  57. this.map = null;
  58. this.lightMap = null;
  59. this.lightMapIntensity = 1.0;
  60. this.aoMap = null;
  61. this.aoMapIntensity = 1.0;
  62. this.emissive = new Color( 0x000000 );
  63. this.emissiveIntensity = 1.0;
  64. this.emissiveMap = null;
  65. this.bumpMap = null;
  66. this.bumpScale = 1;
  67. this.normalMap = null;
  68. this.normalMapType = TangentSpaceNormalMap;
  69. this.normalScale = new Vector2( 1, 1 );
  70. this.displacementMap = null;
  71. this.displacementScale = 1;
  72. this.displacementBias = 0;
  73. this.specularMap = null;
  74. this.alphaMap = null;
  75. this.envMap = null;
  76. this.combine = MultiplyOperation;
  77. this.reflectivity = 1;
  78. this.refractionRatio = 0.98;
  79. this.wireframe = false;
  80. this.wireframeLinewidth = 1;
  81. this.wireframeLinecap = 'round';
  82. this.wireframeLinejoin = 'round';
  83. this.flatShading = false;
  84. this.setValues( parameters );
  85. }
  86. copy( source ) {
  87. super.copy( source );
  88. this.color.copy( source.color );
  89. this.specular.copy( source.specular );
  90. this.shininess = source.shininess;
  91. this.map = source.map;
  92. this.lightMap = source.lightMap;
  93. this.lightMapIntensity = source.lightMapIntensity;
  94. this.aoMap = source.aoMap;
  95. this.aoMapIntensity = source.aoMapIntensity;
  96. this.emissive.copy( source.emissive );
  97. this.emissiveMap = source.emissiveMap;
  98. this.emissiveIntensity = source.emissiveIntensity;
  99. this.bumpMap = source.bumpMap;
  100. this.bumpScale = source.bumpScale;
  101. this.normalMap = source.normalMap;
  102. this.normalMapType = source.normalMapType;
  103. this.normalScale.copy( source.normalScale );
  104. this.displacementMap = source.displacementMap;
  105. this.displacementScale = source.displacementScale;
  106. this.displacementBias = source.displacementBias;
  107. this.specularMap = source.specularMap;
  108. this.alphaMap = source.alphaMap;
  109. this.envMap = source.envMap;
  110. this.combine = source.combine;
  111. this.reflectivity = source.reflectivity;
  112. this.refractionRatio = source.refractionRatio;
  113. this.wireframe = source.wireframe;
  114. this.wireframeLinewidth = source.wireframeLinewidth;
  115. this.wireframeLinecap = source.wireframeLinecap;
  116. this.wireframeLinejoin = source.wireframeLinejoin;
  117. this.flatShading = source.flatShading;
  118. return this;
  119. }
  120. }
  121. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  122. export { MeshPhongMaterial };