MeshPhongMaterial.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. * @author alteredq / http://alteredqualia.com/
  4. *
  5. * parameters = {
  6. * color: <hex>,
  7. * emissive: <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. * bumpMap: new THREE.Texture( <Image> ),
  21. * bumpScale: <float>,
  22. *
  23. * normalMap: new THREE.Texture( <Image> ),
  24. * normalScale: <Vector2>,
  25. *
  26. * specularMap: new THREE.Texture( <Image> ),
  27. *
  28. * alphaMap: new THREE.Texture( <Image> ),
  29. *
  30. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  31. * combine: THREE.Multiply,
  32. * reflectivity: <float>,
  33. * refractionRatio: <float>,
  34. *
  35. * shading: THREE.SmoothShading,
  36. * blending: THREE.NormalBlending,
  37. * depthTest: <bool>,
  38. * depthWrite: <bool>,
  39. *
  40. * wireframe: <boolean>,
  41. * wireframeLinewidth: <float>,
  42. *
  43. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  44. *
  45. * skinning: <bool>,
  46. * morphTargets: <bool>,
  47. * morphNormals: <bool>,
  48. *
  49. * fog: <bool>
  50. * }
  51. */
  52. THREE.MeshPhongMaterial = function ( parameters ) {
  53. THREE.Material.call( this );
  54. this.type = 'MeshPhongMaterial';
  55. this.color = new THREE.Color( 0xffffff ); // diffuse
  56. this.emissive = new THREE.Color( 0x000000 );
  57. this.specular = new THREE.Color( 0x111111 );
  58. this.shininess = 30;
  59. this.metal = false;
  60. this.wrapAround = false;
  61. this.wrapRGB = new THREE.Vector3( 1, 1, 1 );
  62. this.map = null;
  63. this.lightMap = null;
  64. this.lightMapIntensity = 1.0;
  65. this.aoMap = null;
  66. this.aoMapIntensity = 1.0;
  67. this.bumpMap = null;
  68. this.bumpScale = 1;
  69. this.normalMap = null;
  70. this.normalScale = new THREE.Vector2( 1, 1 );
  71. this.specularMap = null;
  72. this.alphaMap = null;
  73. this.envMap = null;
  74. this.combine = THREE.MultiplyOperation;
  75. this.reflectivity = 1;
  76. this.refractionRatio = 0.98;
  77. this.fog = true;
  78. this.shading = THREE.SmoothShading;
  79. this.wireframe = false;
  80. this.wireframeLinewidth = 1;
  81. this.wireframeLinecap = 'round';
  82. this.wireframeLinejoin = 'round';
  83. this.vertexColors = THREE.NoColors;
  84. this.skinning = false;
  85. this.morphTargets = false;
  86. this.morphNormals = false;
  87. this.setValues( parameters );
  88. };
  89. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  90. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  91. THREE.MeshPhongMaterial.prototype.clone = function () {
  92. var material = new THREE.MeshPhongMaterial();
  93. THREE.Material.prototype.clone.call( this, material );
  94. material.color.copy( this.color );
  95. material.emissive.copy( this.emissive );
  96. material.specular.copy( this.specular );
  97. material.shininess = this.shininess;
  98. material.metal = this.metal;
  99. material.wrapAround = this.wrapAround;
  100. material.wrapRGB.copy( this.wrapRGB );
  101. material.map = this.map;
  102. material.lightMap = this.lightMap;
  103. material.lightMapIntensity = this.lightMapIntensity;
  104. material.aoMap = this.aoMap;
  105. material.aoMapIntensity = this.aoMapIntensity;
  106. material.bumpMap = this.bumpMap;
  107. material.bumpScale = this.bumpScale;
  108. material.normalMap = this.normalMap;
  109. material.normalScale.copy( this.normalScale );
  110. material.specularMap = this.specularMap;
  111. material.alphaMap = this.alphaMap;
  112. material.envMap = this.envMap;
  113. material.combine = this.combine;
  114. material.reflectivity = this.reflectivity;
  115. material.refractionRatio = this.refractionRatio;
  116. material.fog = this.fog;
  117. material.shading = this.shading;
  118. material.wireframe = this.wireframe;
  119. material.wireframeLinewidth = this.wireframeLinewidth;
  120. material.wireframeLinecap = this.wireframeLinecap;
  121. material.wireframeLinejoin = this.wireframeLinejoin;
  122. material.vertexColors = this.vertexColors;
  123. material.skinning = this.skinning;
  124. material.morphTargets = this.morphTargets;
  125. material.morphNormals = this.morphNormals;
  126. return material;
  127. };
  128. THREE.MeshPhongMaterial.prototype.toJSON = function () {
  129. var data = THREE.Material.prototype.toJSON.call( this );
  130. data.color = this.color.getHex();
  131. data.emissive = this.emissive.getHex();
  132. data.specular = this.specular.getHex();
  133. data.shininess = this.shininess;
  134. if ( this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  135. if ( this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  136. if ( this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  137. if ( this.side !== THREE.FrontSide ) data.side = this.side;
  138. return data;
  139. };
粤ICP备19079148号