Material.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. * @author alteredq / http://alteredqualia.com/
  4. */
  5. THREE.Material = function () {
  6. THREE.EventDispatcher.call( this );
  7. this.id = THREE.MaterialIdCount ++;
  8. this.name = '';
  9. this.side = THREE.FrontSide;
  10. this.opacity = 1;
  11. this.transparent = false;
  12. this.blending = THREE.NormalBlending;
  13. this.blendSrc = THREE.SrcAlphaFactor;
  14. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  15. this.blendEquation = THREE.AddEquation;
  16. this.depthTest = true;
  17. this.depthWrite = true;
  18. this.polygonOffset = false;
  19. this.polygonOffsetFactor = 0;
  20. this.polygonOffsetUnits = 0;
  21. this.alphaTest = 0;
  22. this.overdraw = false; // Boolean for fixing antialiasing gaps in CanvasRenderer
  23. this.visible = true;
  24. this.needsUpdate = true;
  25. };
  26. THREE.Material.prototype.setValues = function ( values ) {
  27. if ( values === undefined ) return;
  28. for ( var key in values ) {
  29. var newValue = values[ key ];
  30. if ( newValue === undefined ) {
  31. console.warn( 'THREE.Material: \'' + key + '\' parameter is undefined.' );
  32. continue;
  33. }
  34. if ( key in this ) {
  35. var currentValue = this[ key ];
  36. if ( currentValue instanceof THREE.Color && newValue instanceof THREE.Color ) {
  37. currentValue.copy( newValue );
  38. } else if ( currentValue instanceof THREE.Color ) {
  39. currentValue.set( newValue );
  40. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  41. currentValue.copy( newValue );
  42. } else {
  43. this[ key ] = newValue;
  44. }
  45. }
  46. }
  47. };
  48. THREE.Material.prototype.clone = function ( material ) {
  49. if ( material === undefined ) material = new THREE.Material();
  50. material.name = this.name;
  51. material.side = this.side;
  52. material.opacity = this.opacity;
  53. material.transparent = this.transparent;
  54. material.blending = this.blending;
  55. material.blendSrc = this.blendSrc;
  56. material.blendDst = this.blendDst;
  57. material.blendEquation = this.blendEquation;
  58. material.depthTest = this.depthTest;
  59. material.depthWrite = this.depthWrite;
  60. material.polygonOffset = this.polygonOffset;
  61. material.polygonOffsetFactor = this.polygonOffsetFactor;
  62. material.polygonOffsetUnits = this.polygonOffsetUnits;
  63. material.alphaTest = this.alphaTest;
  64. material.overdraw = this.overdraw;
  65. material.visible = this.visible;
  66. return material;
  67. };
  68. THREE.Material.prototype.dispose = function () {
  69. this.dispatchEvent( { type: 'dispose' } );
  70. };
  71. THREE.MaterialIdCount = 0;