MeshMatcapMaterial.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. * opacity: <float>,
  11. *
  12. * matcap: new THREE.Texture( <Image> ),
  13. *
  14. * map: new THREE.Texture( <Image> ),
  15. *
  16. * bumpMap: new THREE.Texture( <Image> ),
  17. * bumpScale: <float>,
  18. *
  19. * normalMap: new THREE.Texture( <Image> ),
  20. * normalMapType: THREE.TangentSpaceNormalMap,
  21. * normalScale: <Vector2>,
  22. *
  23. * displacementMap: new THREE.Texture( <Image> ),
  24. * displacementScale: <float>,
  25. * displacementBias: <float>,
  26. *
  27. * alphaMap: new THREE.Texture( <Image> ),
  28. *
  29. * skinning: <bool>,
  30. * morphTargets: <bool>,
  31. * morphNormals: <bool>
  32. * }
  33. */
  34. function MeshMatcapMaterial( parameters ) {
  35. Material.call( this );
  36. this.defines = { 'MATCAP': '' };
  37. this.type = 'MeshMatcapMaterial';
  38. this.color = new Color( 0xffffff ); // diffuse
  39. this.matcap = null;
  40. this.map = null;
  41. this.bumpMap = null;
  42. this.bumpScale = 1;
  43. this.normalMap = null;
  44. this.normalMapType = TangentSpaceNormalMap;
  45. this.normalScale = new Vector2( 1, 1 );
  46. this.displacementMap = null;
  47. this.displacementScale = 1;
  48. this.displacementBias = 0;
  49. this.alphaMap = null;
  50. this.skinning = false;
  51. this.morphTargets = false;
  52. this.morphNormals = false;
  53. this.lights = false;
  54. this.setValues( parameters );
  55. // a matcap is required
  56. if ( this.matcap === null ) {
  57. var canvas = document.createElement( 'canvas' );
  58. canvas.width = 1;
  59. canvas.height = 1;
  60. var context = canvas.getContext( '2d' );
  61. context.fillStyle = '#fff';
  62. context.fillRect( 0, 0, 1, 1 );
  63. this.matcap = new THREE.CanvasTexture( canvas );
  64. }
  65. }
  66. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  67. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  68. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  69. MeshMatcapMaterial.prototype.copy = function ( source ) {
  70. Material.prototype.copy.call( this, source );
  71. this.defines = { 'MATCAP': '' };
  72. this.color.copy( source.color );
  73. this.matcap = source.matcap;
  74. this.map = source.map;
  75. this.bumpMap = source.bumpMap;
  76. this.bumpScale = source.bumpScale;
  77. this.normalMap = source.normalMap;
  78. this.normalMapType = source.normalMapType;
  79. this.normalScale.copy( source.normalScale );
  80. this.displacementMap = source.displacementMap;
  81. this.displacementScale = source.displacementScale;
  82. this.displacementBias = source.displacementBias;
  83. this.alphaMap = source.alphaMap;
  84. this.skinning = source.skinning;
  85. this.morphTargets = source.morphTargets;
  86. this.morphNormals = source.morphNormals;
  87. return this;
  88. };
  89. export { MeshMatcapMaterial };