MeshPhongMaterial.js 4.1 KB

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